异常信息如下:
注意以上类,翻开源码:
package com.alibaba.dubbo.rpc.cluster.support; /** * 失败转移,当出现失败,重试其它服务器,通常用于读操作,但重试会带来更长延迟。 * * <a href="http://en.wikipedia.org/wiki/Failover">Failover</a> * * @author william.liangf * @author chao.liuc */ public class FailoverClusterInvoker<T> extends AbstractClusterInvoker<T> { private static final Logger logger = LoggerFactory.getLogger(FailoverClusterInvoker.class); public FailoverClusterInvoker(Directory<T> directory) { super(directory); } @SuppressWarnings({ "unchecked", "rawtypes" }) public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException { List<Invoker<T>> copyinvokers = invokers; checkInvokers(copyinvokers, invocation); int len = getUrl().getMethodParameter(invocation.getMethodName(), Constants.RETRIES_KEY, Constants.DEFAULT_RETRIES) + 1; if (len <= 0) { len = 1; } // retry loop. RpcException le = null; // last exception. List<Invoker<T>> invoked = new ArrayList<Invoker<T>>(copyinvokers.size()); // invoked invokers. Set<String> providers = new HashSet<String>(len); for (int i = 0; i < len; i++) { //重试时,进行重新选择,避免重试时invoker列表已发生变化. //注意:如果列表发生了变化,那么invoked判断会失效,因为invoker示例已经改变 if (i > 0) { checkWheatherDestoried(); copyinvokers = list(invocation); //重新检查一下 checkInvokers(copyinvokers, invocation); } Invoker<T> invoker = select(loadbalance, invocation, copyinvokers, invoked); invoked.add(invoker); RpcContext.getContext().setInvokers((List)invoked); try { Result result = invoker.invoke(invocation); if (le != null && logger.isWarnEnabled()) { logger.warn("Although retry the method " + invocation.getMethodName() + " in the service " + getInterface().getName() + " was successful by the provider " + invoker.getUrl().getAddress() + ", but there have been failed providers " + providers + " (" + providers.size() + "/" + copyinvokers.size() + ") from the registry " + directory.getUrl().getAddress() + " on the consumer " + NetUtils.getLocalHost() + " using the dubbo version " + Version.getVersion() + ". Last error is: " + le.getMessage(), le); } return result; } catch (RpcException e) { if (e.isBiz()) { // biz exception. throw e; } le = e; } catch (Throwable e) { le = new RpcException(e.getMessage(), e); } finally { providers.add(invoker.getUrl().getAddress()); } } throw new RpcException(le != null ? le.getCode() : 0, "Failed to invoke the method " + invocation.getMethodName() + " in the service " + getInterface().getName() + ". Tried " + len + " times of the providers " + providers + " (" + providers.size() + "/" + copyinvokers.size() + ") from the registry " + directory.getUrl().getAddress() + " on the consumer " + NetUtils.getLocalHost() + " using the dubbo version " + Version.getVersion() + ". Last error is: " + (le != null ? le.getMessage() : ""), le != null && le.getCause() != null ? le.getCause() : le); } }
跟踪异常栈,可以抛出异常在以下地方:
关注初始报错信息:
java.util.concurrent.ExecutionException: com.alibaba.dubbo.rpc.RpcException:
Failed to invoke the method query in the service cn.fraudmetrix.skuld.api.client.intf.IListValueService.
Tried 1 times of the providers [192.168.121.230:20880] (1/10) from the registry 192.168.47.83:2181 on the consumer 192.168.55.67
using the dubbo version 2.5.3. Last error is: null
注意以上是null, 问题就在这里,网上找了一些资料,也没发现相关的原因,只能本地翻看源码论证可能性:
可能性1: 请求超时:
异常信息:
Failed to invoke the method query in the service cn.fraudmetrix.skuld.api.client.intf.IListValueService.
Tried 3 times of the providers [10.57.240.10:20880] (1/1) from the registry 192.168.6.55:2181 on the consumer 10.57.240.10
using the dubbo version 2.5.3. Last error is:
Invoke remote method timeout. method: query, provider: dubbo://10.57.240.10:20880/....
后面有具体的原因,timeout,一目了然。
可能性2:服务提供者未启动:
异常信息:
om.alibaba.dubbo.rpc.RpcException: Forbid consumer 10.57.240.10 access service cn.fraudmetrix.skuld.api.client.intf.IListValueService from registry 192.168.6.55:2181 use dubbo version 2.5.3, Please check registry access list (whitelist/blacklist). at com.alibaba.dubbo.registry.integration.RegistryDirectory.doList(RegistryDirectory.java:579) at com.alibaba.dubbo.rpc.cluster.directory.AbstractDirectory.list(AbstractDirectory.java:73) at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.list(AbstractClusterInvoker.java:260) at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:219) at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72) at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52) at com.alibaba.dubbo.common.bytecode.proxy0.query(proxy0.java) at cn.fraudmetrix.skuld.dubbotest.ValueQueryTest.runTest(ValueQueryTest.java:70) at cn.fraudmetrix.skuld.dubbotest.App.main(App.java:15)
在AbstractClusterInvoker中有以下代码:
List<Invoker<T>> invokers = doList(invocation);
直接异常了。
可能性3:服务提供者启动,跳过验证后宕机:
异常信息:
Failed to invoke the method query in the service cn.fraudmetrix.skuld.api.client.intf.IListValueService.
Tried 3 times of the providers [10.57.240.10:20880] (1/1) from the registry 192.168.6.55:2181 on the consumer 10.57.240.10
using the dubbo version 2.5.3. Last error is:
Failed to invoke remote method: query, provider: dubbo://10.57.240.10:20880/.....
后面也有相关的原因。
现在报个null还不好找原因啊。