dubbo No provider错误排查方法

dubbo No provider这个错误在开发过程中经常遇到,本文记录了一些基础方法,让未对dubbo远离进行系统了解的朋友,更快速的找到问题。治标不治本,如果平时大量使用dubbo还是应该去了解它的原理。

错误日志实例

  • 这个是我从测试环境中中截取的部分日志内容
    1
    2
    3
    4
    5
    6
    7
    8
    com.alibaba.dubbo.rpc.RpcException: No provider available from registry test0.zookeeper-common.xxxx.xxx.local:2181 for service zw/com.xxx.service.BaseGoodsService:1.0.0 on consumer xx.xx.xx.xx use dubbo version 2.6.2, please check status of providers(disabled, not registered or in blacklist).
    at com.alibaba.dubbo.registry.integration.RegistryDirectory.doList(RegistryDirectory.java:575)
    at com.alibaba.dubbo.rpc.cluster.directory.AbstractDirectory.list(AbstractDirectory.java:74)
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.list(AbstractClusterInvoker.java:271)
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:232)
    at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:75)
    at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
    at com.alibaba.dubbo.common.bytecode.proxy4.findById(proxy4.java)

错误原因

根本原因是服务提供者找不到或者服务提供者没有实现该方法。

那么可能的错误原因有:

  1. 服务提供者不在线了
  2. 服务提供者注册的服务的和客户端不匹配
  3. 服务提供者本来就没有实现该方法

排查方法

错误日志中的关键信息: methodName, serviceKey, address

  1. 注册中心是否有服务提供者
  2. 服务提供者的address和日志中打印的address是否相同
  3. 比对serviceKey和注册中心注册的是否相同的

servicekey代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public String getServiceKey() {
String inf = getServiceInterface();
if (inf == null) return null;
StringBuilder buf = new StringBuilder();
String group = getParameter(Constants.GROUP_KEY);
if (group != null && group.length() > 0) {
buf.append(group).append("/");
}
buf.append(inf);
String version = getParameter(Constants.VERSION_KEY);
if (version != null && version.length() > 0) {
buf.append(":").append(version);
}
return buf.toString();
}

日志中的servcieKey的格式: {group}/xxxx.xxx.xxxService:{version}, 所以service对比内容就是group, version, 服务的全路径