Search in sources :

Example 86 with RpcException

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);
    }
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException)

Example 87 with RpcException

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);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RpcException(org.apache.dubbo.rpc.RpcException)

Example 88 with RpcException

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);
    }
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException)

Example 89 with RpcException

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"));
    }
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) Invoker(org.apache.dubbo.rpc.Invoker) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 90 with RpcException

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);
    }
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException) Gson(com.google.gson.Gson)

Aggregations

RpcException (org.apache.dubbo.rpc.RpcException)102 URL (org.apache.dubbo.common.URL)37 Test (org.junit.jupiter.api.Test)29 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)28 Result (org.apache.dubbo.rpc.Result)21 Invocation (org.apache.dubbo.rpc.Invocation)17 ArrayList (java.util.ArrayList)15 AppResponse (org.apache.dubbo.rpc.AppResponse)13 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)13 Invoker (org.apache.dubbo.rpc.Invoker)13 IOException (java.io.IOException)9 List (java.util.List)9 Method (java.lang.reflect.Method)8 Gson (com.google.gson.Gson)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 HashMap (java.util.HashMap)5 RemotingException (org.apache.dubbo.remoting.RemotingException)5 TException (org.apache.thrift.TException)5 SocketTimeoutException (java.net.SocketTimeoutException)4 CountDownLatch (java.util.concurrent.CountDownLatch)4