use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class RedisRegistry method doUnregister.
@Override
public void doUnregister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
try {
redisClient.hdel(key, value);
redisClient.publish(key, UNREGISTER);
} catch (Throwable t) {
throw new RpcException("Failed to unregister service to redis registry. registry: " + url.getAddress() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class RedisRegistry method doSubscribe.
@Override
public void doSubscribe(final URL url, final NotifyListener listener) {
String service = toServicePath(url);
Notifier notifier = notifiers.get(service);
if (notifier == null) {
Notifier newNotifier = new Notifier(service);
notifiers.putIfAbsent(service, newNotifier);
notifier = notifiers.get(service);
if (notifier == newNotifier) {
notifier.start();
}
}
try {
if (service.endsWith(ANY_VALUE)) {
admin = true;
Set<String> keys = redisClient.scan(service);
if (CollectionUtils.isNotEmpty(keys)) {
Map<String, Set<String>> serviceKeys = new HashMap<>();
for (String key : keys) {
String serviceKey = toServicePath(key);
Set<String> sk = serviceKeys.computeIfAbsent(serviceKey, k -> new HashSet<>());
sk.add(key);
}
for (Set<String> sk : serviceKeys.values()) {
doNotify(sk, url, Collections.singletonList(listener));
}
}
} else {
doNotify(redisClient.scan(service + PATH_SEPARATOR + ANY_VALUE), url, Collections.singletonList(listener));
}
} catch (Throwable t) {
throw new RpcException("Failed to subscribe service from redis registry. registry: " + url.getAddress() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class RedisRegistry method doRegister.
@Override
public void doRegister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
try {
redisClient.hset(key, value, expire);
redisClient.publish(key, REGISTER);
} catch (Throwable t) {
throw new RpcException("Failed to register service to redis registry. registry: " + url.getAddress() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class RegistryDirectoryTest method testDestroy.
/**
* When destroying, RegistryDirectory should: 1. be disconnected from Registry 2. destroy all invokers
*/
@Test
public void testDestroy() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1,getXXX2,getXXX3"));
registryDirectory.notify(serviceUrls);
List<Invoker> invokers = registryDirectory.list(invocation);
Assertions.assertTrue(registryDirectory.isAvailable());
Assertions.assertTrue(invokers.get(0).isAvailable());
registryDirectory.destroy();
Assertions.assertFalse(registryDirectory.isAvailable());
Assertions.assertFalse(invokers.get(0).isAvailable());
registryDirectory.destroy();
List<Invoker<RegistryDirectoryTest>> cachedInvokers = registryDirectory.getInvokers();
Map<URL, Invoker<RegistryDirectoryTest>> urlInvokerMap = registryDirectory.getUrlInvokerMap();
Assertions.assertNull(cachedInvokers);
Assertions.assertEquals(0, urlInvokerMap.size());
// List<U> urls = mockRegistry.getSubscribedUrls();
RpcInvocation inv = new RpcInvocation();
try {
registryDirectory.list(inv);
fail();
} catch (RpcException e) {
Assertions.assertTrue(e.getMessage().contains("already destroyed"));
}
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class EtcdServiceDiscovery method doRegister.
@Override
public void doRegister(ServiceInstance serviceInstance) {
try {
String path = toPath(serviceInstance);
// etcdClient.createEphemeral(path);
etcdClient.putEphemeral(path, new Gson().toJson(serviceInstance));
services.add(serviceInstance.getServiceName());
} catch (Throwable e) {
throw new RpcException("Failed to register " + serviceInstance + " to etcd " + etcdClient.getUrl() + ", cause: " + (OptionUtil.isProtocolError(e) ? "etcd3 registry may not be supported yet or etcd3 registry is not available." : e.getMessage()), e);
}
}
Aggregations