Search in sources :

Example 1 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project pinpoint by naver.

the class DubboProviderApplication method startWithBootstrap.

private static void startWithBootstrap() {
    ServiceConfig<GreetingsServiceImpl> service = new ServiceConfig<>();
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider")).registry(new RegistryConfig("zookeeper://" + ZOOKEEPER_HOST + ":2181")).service(service).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 2 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class DubboServiceProviderBootstrap method multipleRegistries.

private static void multipleRegistries() {
    ProtocolConfig restProtocol = new ProtocolConfig();
    restProtocol.setName("rest");
    restProtocol.setId("rest");
    restProtocol.setPort(-1);
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
    RegistryConfig serviceRegistry = new RegistryConfig();
    serviceRegistry.setId("serviceRegistry");
    serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service");
    ServiceConfig<EchoService> echoService = new ServiceConfig<>();
    echoService.setInterface(EchoService.class.getName());
    echoService.setRef(new EchoServiceImpl());
    // echoService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ServiceConfig<UserService> userService = new ServiceConfig<>();
    userService.setInterface(UserService.class.getName());
    userService.setRef(new UserServiceImpl());
    userService.setProtocol(restProtocol);
    // userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-provider-demo");
    applicationConfig.setMetadataType("remote");
    DubboBootstrap.getInstance().application(applicationConfig).registries(Arrays.asList(interfaceRegistry, serviceRegistry)).protocol(builder -> builder.port(-1).name("dubbo")).metadataReport(new MetadataReportConfig("zookeeper://127.0.0.1:2181")).service(echoService).service(userService).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Arrays(java.util.Arrays) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 3 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class EtcdDubboServiceProviderBootstrap method multipleRegistries.

private static void multipleRegistries() {
    ProtocolConfig restProtocol = new ProtocolConfig();
    restProtocol.setName("rest");
    restProtocol.setId("rest");
    restProtocol.setPort(-1);
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("etcd3://127.0.0.1:2379");
    RegistryConfig serviceRegistry = new RegistryConfig();
    serviceRegistry.setId("serviceRegistry");
    serviceRegistry.setAddress("etcd3://127.0.0.1:2379?registry-type=service");
    ServiceConfig<EchoService> echoService = new ServiceConfig<>();
    echoService.setInterface(EchoService.class.getName());
    echoService.setRef(new EchoServiceImpl());
    // echoService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ServiceConfig<UserService> userService = new ServiceConfig<>();
    userService.setInterface(UserService.class.getName());
    userService.setRef(new UserServiceImpl());
    userService.setProtocol(restProtocol);
    // userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-provider-demo");
    // applicationConfig.setMetadataType("remote");
    DubboBootstrap.getInstance().application(applicationConfig).registries(Arrays.asList(interfaceRegistry, serviceRegistry)).protocol(builder -> builder.port(-1).name("dubbo")).service(echoService).service(userService).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 4 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class ServiceBuilderTest method build.

// 
// @Test
// public void Mock() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceBuilder builder = new ServiceBuilder();
// builder.mock("true");
// });
// }
// 
// @Test
// public void Mock1() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceBuilder builder = new ServiceBuilder();
// builder.mock(true);
// });
// }
@Test
void build() {
    MethodConfig method = new MethodConfig();
    ProviderConfig provider = new ProviderConfig();
    ServiceBuilder builder = new ServiceBuilder();
    builder.path("path").addMethod(method).provider(provider).providerIds("providerIds").generic(GENERIC_SERIALIZATION_DEFAULT);
    ServiceConfig config = builder.build();
    ServiceConfig config2 = builder.build();
    assertThat(config.getGeneric(), equalTo(GENERIC_SERIALIZATION_DEFAULT));
    Assertions.assertEquals("path", config.getPath());
    Assertions.assertEquals("providerIds", config.getProviderIds());
    Assertions.assertSame(provider, config.getProvider());
    Assertions.assertTrue(config.getMethods().contains(method));
    Assertions.assertEquals(1, config.getMethods().size());
    Assertions.assertNotSame(config, config2);
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class GenericServiceTest method testGenericInvokeWithBeanSerialization.

@Test
public void testGenericInvokeWithBeanSerialization() throws Exception {
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setInterface(DemoService.class);
    DemoServiceImpl impl = new DemoServiceImpl();
    service.setRef(impl);
    ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:29581?scope=remote&timeout=3000");
    reference.setGeneric(GENERIC_SERIALIZATION_BEAN);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("generic-test")).registry(new RegistryConfig("N/A")).protocol(new ProtocolConfig("dubbo", 29581)).service(service).reference(reference);
    bootstrap.start();
    try {
        GenericService genericService = bootstrap.getCache().get(reference);
        User user = new User();
        user.setName("zhangsan");
        List<User> users = new ArrayList<User>();
        users.add(user);
        Object result = genericService.$invoke("getUsers", new String[] { ReflectUtils.getName(List.class) }, new Object[] { JavaBeanSerializeUtil.serialize(users, JavaBeanAccessor.METHOD) });
        Assertions.assertTrue(result instanceof JavaBeanDescriptor);
        JavaBeanDescriptor descriptor = (JavaBeanDescriptor) result;
        Assertions.assertTrue(descriptor.isCollectionType());
        Assertions.assertEquals(1, descriptor.propertySize());
        descriptor = (JavaBeanDescriptor) descriptor.getProperty(0);
        Assertions.assertTrue(descriptor.isBeanType());
        Assertions.assertEquals(user.getName(), ((JavaBeanDescriptor) descriptor.getProperty("name")).getPrimitiveProperty());
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ArrayList(java.util.ArrayList) JavaBeanDescriptor(org.apache.dubbo.common.beanutil.JavaBeanDescriptor) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ArrayList(java.util.ArrayList) List(java.util.List) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceConfig (org.apache.dubbo.config.ServiceConfig)26 RegistryConfig (org.apache.dubbo.config.RegistryConfig)19 Test (org.junit.jupiter.api.Test)19 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)18 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)14 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)14 DemoService (org.apache.dubbo.config.spring.api.DemoService)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)9 URL (org.apache.dubbo.common.URL)7 GenericService (org.apache.dubbo.rpc.service.GenericService)7 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)6 ArrayList (java.util.ArrayList)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 List (java.util.List)3 JavaBeanDescriptor (org.apache.dubbo.common.beanutil.JavaBeanDescriptor)2 MethodConfig (org.apache.dubbo.config.MethodConfig)2 ProviderConfig (org.apache.dubbo.config.ProviderConfig)2 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)2 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)2 GenericException (org.apache.dubbo.rpc.service.GenericException)2