首页 > 其他 > 详细

dubbo zookeeper Failed to check the status of the service...No provider available for the service

时间:2020-04-10 20:58:31      阅读:163      评论:0      收藏:0      [点我收藏+]

异常

在dubbo与zookeeper的简单案例中,成功启动provider应用,由于粘贴粗心,在启动consumer应用的时候蹦出一个ERROR

java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_241]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_241]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_241]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_241]
	at com.alibaba.dubbo.config.AbstractConfig.toString(AbstractConfig.java:474) ~[dubbo-2.6.2.jar:2.6.2]
...
Failed to check the status of the service...
...
No provider available for the service...
...

不愿意看记录,可以直接翻到文末找解决办法

调用异常?

于是四处查找,找注解,没问题;找yml配置没问题;找服务器上zookeeper的配置,找aliyun安全组配置,都没问题。找了老长时间,天已经很晚了

第二天才认真去看ERROR后的正常log,log真的很长,一大溜,头天晚上并没有认真往后翻。于是看到以下日志

在consumer应用的相关log是:
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Register: consumer://192.168.43.100/com.icourage.consumeruser.service.TicketService

c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Subscribe: consumer://192.168.43.100/com.icourage.consumeruser.service.TicketService
也就是register和subscribe的是com.icourage.consumeruser.service.TicketService

在provider应用的相关log是:
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Register: dubbo://192.168.43.100:12398/com.icourage.providerticket.service.TicketService

c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Subscribe: provider://192.168.43.100:12398/com.icourage.providerticket.service.TicketService
register和subscribe的是com.icourage.providerticket.service.TicketService
notify的URL:
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Notify urls for subscribe url provider://192.168.43.100:12398/com.icourage.providerticket.service.TicketService

原因

  • provider注册和notify的是com.icourage.providerticket.service.TicketService
  • consumer订阅的是com.icourage.consumeruser.service.TicketService
  • 所以consumer根本找不到这个接口,抛出调用异常

具体原因

provider应用启动类上的 @EnableDubbo 注解会扫描与启动类同级的包及其子包(与Spring..扫描范围相同)是否有 @com.alibaba.dubbo.config.annotation.Service 标识的类,注册的接口是该类的全路径【package name.class name】
consumer应用则会以 @Reference 的接口 refer
resources

解决办法

从上面可以看到是consumer应用中,interface TicketService 所在包有问题,应该是 com.icourage.providerticket.service,所以

  • 调整consumer应用的目录结构
  • 技术分享图片
  • 重新 compile

简单案例源码

PS:保持好的分包、编码习惯他不香吗

dubbo zookeeper Failed to check the status of the service...No provider available for the service

原文:https://www.cnblogs.com/Ycourage/p/12676020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!