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();
}
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();
}
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();
}
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);
}
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();
}
}
Aggregations