buguge - Keep it simple,stupid

知识就是力量,但更重要的,是运用知识的能力why buguge?

导航

dubbo提供者停止服务后zookeeper注册中心节点仍然存在

dubbo服务停掉了,可是zk上面还有该节点,这样的话,客户端在消费的时候就会出现调用失败的情况。造成该问题的原因有很多,开篇先说我的解决方案,是将dubbo版本从2.7.1升级到2.7.3。

 

ok,说完解决方案,接下来简单描述一下这个问题的解决过程。

 

我刚进入YF项目组。今天接到反映,说测试环境在调用下发接口的时候报“内部服务异常”。

检查log,发现dubbo服务调用出现异常:

com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method merIsExistProject in the service com.auth.merchant.api.service.MerProjectService. Tried 1 times of the providers [127.0.0.1:20886] (1/8) from the registry 192.168.40.49:2181 on the consumer 192.168.40.51 using the dubbo version 2.5.3. Last error is: Failed to invoke remote method: merIsExistProject, provider: dubbo://127.0.0.1:20886/com.auth.merchant.api.service.MerProjectService?anyhost=true&application=risk-service-trans-business&bean.name=providers:dubbo:com.auth.merchant.api.service.MerProjectService:1.0.0&check=false&default.deprecated=false&default.dynamic=false&default.register=true&deprecated=false&dubbo=2.0.2&dynamic=false&generic=false&interface=com.auth.merchant.api.service.MerProjectService&methods=updateMerJhLevyProject,queryHall,query,insertMerJhLevy,update,insert,list,delete,listByParam,updateHall,merIsExistProject,listHall,insertBatch,getMerJhLevyProjectList&pid=16218&register=true&release=2.7.1&retries=0&revision=0.0.1-SNAPSHOT&side=consumer&timeout=50000&timestamp=1603070513879&version=1.0.0, cause: com.alibaba.dubbo.remoting.RemotingException: Not found exported service: com.auth.merchant.api.service.MerProjectService.null:1.0.0:20886 in [], may be version or group mismatch , channel: consumer: /192.168.40.51:20886 --> provider: /192.168.40.51:20886, message:RpcInvocation [methodName=merIsExistProject, parameterTypes=[class com.auth.merchant.api.vo.MerJhLevyProjectVo], arguments=[MerJhLevyProject{id=null, jhMerNo=89900000080215728529, levyMerNo=null, levyId=null, projectId=5113}], attachments={path=com.auth.merchant.api.service.MerProjectService, input=398, _isCallBackServiceInvoke=true, dubbo=2.5.3, interface=com.auth.merchant.api.service.MerProjectService, version=1.0.0, timeout=50000}]
com.alibaba.dubbo.remoting.RemotingException: Not found exported service: com.auth.merchant.api.service.MerProjectService.null:1.0.0:20886 in [], may be version or group mismatch , channel: consumer: /192.168.40.51:20886 --> provider: /192.168.40.51:20886, message:RpcInvocation [methodName=merIsExistProject, parameterTypes=[class com.auth.merchant.api.vo.MerJhLevyProjectVo], arguments=[MerJhLevyProject{id=null, jhMerNo=89900000080215728529, levyMerNo=null, levyId=null, projectId=5113}], attachments={path=com.auth.merchant.api.service.MerProjectService, input=398, _isCallBackServiceInvoke=true, dubbo=2.5.3, interface=com.auth.merchant.api.service.MerProjectService, version=1.0.0, timeout=50000}]

 

一个伙伴找运维重启了zookeeper和dubbo服务应用,问题依然存在。

 

我检查了一下dubbo接口定义,调用方和服务方的契约是一致的。

 

异常是dubbo.remoting.RemotingException: Not found exported service,网上搜了一下,未果。

 

后来,从zkui上看服务的providers,发现除了服务器的ip以外,还有好多ip地址。用ZooInspector也证实了这个现象。看来小组里有开发人员的本地服务注册上去了。可是现在他本地并没有起服务。

接下来,从zkui上把这些ip的提供者摘掉,重新调用发现ok了。

 

为什么dubbo服务都停了,zk上却还存在呢?从小组的伙伴了解到,这个问题出现已久。

而我此前用dubbo作为rpc框架的项目,并没有出现这个问题。就是说,服务停掉后,zk上面就不再有这个节点了。

于是,我决定尝试fix掉这个问题。

 

经过对dubbo配置和jar包的不断调整和测试,最后,发现是dubbo版本在作祟。

 

我们知道,zookeeper实现了服务的注册和自动发现。dubbo注册到zk的节点是临时节点。即,服务注册后,zk会增加服务节点;当服务停用后,zk客户端断开,zk服务端会自动删除这个服务节点。

而对于dubbo2.7.1版本呢,zk会把dubbo节点注册为持久节点。

后来,同事发现一篇博客,对此解释得很透彻:https://www.cnblogs.com/goodAndyxublog/p/10878186.html

我们看dubbo-2.7.1与dubbo-2.7.3对AbstractServiceConfig.dynamic的注释:

//public abstract class AbstractServiceConfig

-- dubbo-2.7.3
Whether to register as a dynamic service or not on register center, the value is true, the status will be enabled after the service registered,and it needs to be disabled manually; if you want to disable the service, you also need manual processing.
(baidu翻译:是否在注册中心注册为动态服务,值为true,服务注册后状态为启用,需要手动禁用;如果要禁用该服务,还需要手动处理。)
protected Boolean dynamic = true;

-- dubbo-2.7.1
Whether to register as a dynamic service or not on register center, it the value is false, the status will be disabled after the service registered,and it needs to be enabled manually; if you want to disable the service, you also need manual processing.
(baidu翻译:是否在注册中心注册为动态服务,如果值为false,则服务注册后状态为禁用,需要手动启用;如果要禁用该服务,还需要手动处理。)
protected Boolean dynamic = false;

 

 

 

 

 

 

其他解决方案:baidu:dubbo提供者停止服务后zookeeper临时节点不能自动摘除

 

 

ZKUI截图:

 

 

同事在电脑上部署的新版的dubbo admin。zk连的是测试服务器的。我本地的服务启动后,从这里看,发现却没注册上去。而从zkui和zooinspector里可以看到。同事重启这个dubboadmin服务后,发现才获得更新。如果是这样的话,那看来日后也许在排查问题时也许会导致误判。具体是不是这样,待以后自己亲试再说。

 

posted on 2020-10-22 17:14  buguge  阅读(3949)  评论(0编辑  收藏  举报