use of com.alibaba.dubbo.registry.integration.RegistryDirectory 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.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_Provider.
/**
* 测试针对某个provider的Override规则
*/
@Test
public void testNofityOverrideUrls_Provider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
//一个一样,一个不一样
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
Invoker<?> bInvoker = invokers.get(1);
Assert.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
Assert.assertEquals("4", bInvoker.getUrl().getParameter("timeout"));
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method test_NotifiedDubbo1.
//测试调用和registry url的path无关
@Test
public void test_NotifiedDubbo1() {
URL errorPathUrl = URL.valueOf("notsupport:/" + "xxx" + "?refer=" + URL.encode("interface=" + service));
RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
List<URL> serviceUrls = new ArrayList<URL>();
URL Dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true");
serviceUrls.add(Dubbo1URL.addParameter("methods", "getXXX"));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotified_WithDuplicateUrls.
@Test
public void testNotified_WithDuplicateUrls() {
List<URL> serviceUrls = new ArrayList<URL>();
// ignore error log
serviceUrls.add(SERVICEURL);
serviceUrls.add(SERVICEURL);
RegistryDirectory registryDirectory = getRegistryDirectory();
registryDirectory.notify(serviceUrls);
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testParmeterRoute.
/**
* When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
*/
@Test
public void testParmeterRoute() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation(Constants.$INVOKE, new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
}
Aggregations