use of org.apache.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 org.apache.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("org.apache.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20888/org.apache.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
use of org.apache.dubbo.registry.RegistryService in project dubbo by alibaba.
the class DubboRegistryFactory method createRegistry.
@Override
public Registry createRegistry(URL url) {
url = getRegistryURL(url);
List<URL> urls = new ArrayList<>();
urls.add(url.removeParameter(BACKUP_KEY));
String backup = url.getParameter(BACKUP_KEY);
if (backup != null && backup.length() > 0) {
String[] addresses = COMMA_SPLIT_PATTERN.split(backup);
for (String address : addresses) {
urls.add(url.setAddress(address));
}
}
RegistryDirectory<RegistryService> directory = new RegistryDirectory<>(RegistryService.class, url.addParameter(INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(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.setRouterChain(RouterChain.buildChain(url));
directory.notify(urls);
directory.subscribe(new URL(CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
return registry;
}
use of org.apache.dubbo.registry.RegistryService in project dubbo by alibaba.
the class ConfigTest method testDelayFixedTime.
@Test
public void testDelayFixedTime() throws Exception {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-fixed-time.xml");
ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService");
assertNull(urls);
int i = 0;
while ((i++) < 60 && urls == null) {
urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService");
Thread.sleep(10);
}
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20888/org.apache.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
use of org.apache.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("org.apache.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/org.apache.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
Aggregations