use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.
the class ConfigTest method testAnnotation.
@Test
public void testAnnotation() {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
try {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml");
consumerContext.start();
try {
AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction");
String hello = annotationAction.doSayName("hello");
assertEquals("annotation:hello", hello);
} finally {
consumerContext.stop();
consumerContext.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
} finally {
exporter.unexport();
}
}
use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.
the class ConfigTest method testMultiRegistry.
@Test
public void testMultiRegistry() {
SimpleRegistryService registryService1 = new SimpleRegistryService();
Exporter<RegistryService> exporter1 = SimpleRegistryExporter.export(4545, registryService1);
SimpleRegistryService registryService2 = new SimpleRegistryService();
Exporter<RegistryService> exporter2 = SimpleRegistryExporter.export(4546, registryService2);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-registry.xml");
ctx.start();
try {
List<URL> urls1 = registryService1.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNull(urls1);
List<URL> urls2 = registryService2.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls2);
assertEquals(1, urls2.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20880/com.alibaba.dubbo.config.spring.api.DemoService", urls2.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter1.unexport();
exporter2.unexport();
}
}
use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.
the class ConfigTest method testDelayOnInitialized.
@Test
public void testDelayOnInitialized() throws Exception {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml");
//ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.
the class DubboRegistryFactory method createRegistry.
public Registry createRegistry(URL url) {
url = getRegistryURL(url);
List<URL> urls = new ArrayList<URL>();
urls.add(url.removeParameter(Constants.BACKUP_KEY));
String backup = url.getParameter(Constants.BACKUP_KEY);
if (backup != null && backup.length() > 0) {
String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup);
for (String address : addresses) {
urls.add(url.setAddress(address));
}
}
RegistryDirectory<RegistryService> directory = new RegistryDirectory<RegistryService>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString()));
Invoker<RegistryService> registryInvoker = cluster.join(directory);
RegistryService registryService = proxyFactory.getProxy(registryInvoker);
DubboRegistry registry = new DubboRegistry(registryInvoker, registryService);
directory.setRegistry(registry);
directory.setProtocol(protocol);
directory.notify(urls);
directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
return registry;
}
use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.
the class ConfigTest method testMultiProtocolRegister.
@Test
public void testMultiProtocolRegister() {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml");
ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
Aggregations