Dubbo抛出Failed to subscribe consumer://192.168.238.1/com.alibaba.dubbo.registry.RegistryService错误

本文将解决在学习Dubbo的时候出现 Failed to subscribe consumer://192.168.238.1/com.alibaba.dubbo.registry.RegistryService 错误

最近在学习Dubbo时,遇到了“java.lang.IllegalStateException: Failed to subscribe consumer://192.168.238.1/com.alibaba.dubbo.registry.RegistryService”错误信息。Dubbo采用Zookeeper作为注册中心。具体错误堆栈信息如下:

Exception in thread "main" java.lang.IllegalStateException: Failed to subscribe consumer://192.168.238.1/com.alibaba.dubbo.registry.RegistryService?application=demo-provider&callbacks=10000&connect.timeout=10000&dubbo=2.5.3&interface=com.alibaba.dubbo.registry.RegistryService&lazy=true&methods=lookup,unsubscribe,subscribe,unregister,register&pid=304200&reconnect=false&sticky=true&subscribe.1.callback=true&timeout=10000&timestamp=1555682409594&unsubscribe.1.callback=false, cause: Failed to invoke the method subscribe in the service com.alibaba.dubbo.registry.RegistryService. Tried 3 times of the providers [127.0.0.1:2181] (1/1) from the registry 127.0.0.1:2181 on the consumer 192.168.238.1 using the dubbo version 2.5.3. Last error is: Invoke remote method timeout. 
	at com.alibaba.dubbo.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:206)
	at com.alibaba.dubbo.registry.integration.RegistryDirectory.subscribe(RegistryDirectory.java:133)
	at com.alibaba.dubbo.registry.dubbo.DubboRegistryFactory.createRegistry(DubboRegistryFactory.java:80)
	at com.alibaba.dubbo.registry.support.AbstractRegistryFactory.getRegistry(AbstractRegistryFactory.java:94)
	at com.alibaba.dubbo.registry.RegistryFactory$Adpative.getRegistry(RegistryFactory$Adpative.java)
	at com.alibaba.dubbo.registry.integration.RegistryProtocol.getRegistry(RegistryProtocol.java:190)
	at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:109)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:53)
	at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:54)
	at com.alibaba.dubbo.rpc.Protocol$Adpative.export(Protocol$Adpative.java)
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:485)
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:281)
	at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:242)
	at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:143)
	at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:109)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:855)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
	at com.huangx.dubbo.provider.Provider.main(Provider.java:11)
Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method subscribe in the service com.alibaba.dubbo.registry.RegistryService. Tried 3 times of the providers [127.0.0.1:2181] (1/1) from the registry 127.0.0.1:2181 on the consumer 192.168.238.1 using the dubbo version 2.5.3. Last error is: Invoke remote method timeout. method: subscribe, provider: dubbo://127.0.0.1:2181/com.alibaba.dubbo.registry...
	at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:101)
	at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:227)
	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.subscribe(proxy0.java)
	at com.alibaba.dubbo.registry.dubbo.DubboRegistry.doSubscribe(DubboRegistry.java:138)
	at com.alibaba.dubbo.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:189)
	... 23 more
Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout. start time: 2019-04-19 22:00:34.555, end time: 2019-04-19 22:00:44.568, client elapsed: 10 ms, server elapsed: 10002 ms, timeout: 10000 ms, request: Request [id=4, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=subscribe, ...
	at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:107)
	at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:84)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:96)
	at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:144)
	at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:53)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:48)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:74)
	at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
	at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:77)
	... 29 more

根据上面的日志得知时订阅失败,等待服务响应超时。

解决思路如下:

(1)查看是不是ZooKeeper出现了问题,打开Zookeeper终端,出现下面日志:

2019-04-19 22:00:23,883 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@383] - Exception causing close of session 0x0: Len error -625229312
2019-04-19 22:00:23,885 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1040] - Closed socket connection for client /192.168.238.1:1723 (no session established for client)
2019-04-19 22:00:28,710 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /192.168.238.1:1728
2019-04-19 22:00:28,833 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@383] - Exception causing close of session 0x0: Len error -625229312
2019-04-19 22:00:28,836 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1040] - Closed socket connection for client /192.168.238.1:1728 (no session established for client)
2019-04-19 22:00:34,556 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@215] - Accepted socket connection from /192.168.238.1:1734

Zookeeper拒绝连接。解决办法:关闭zookeeper,删除zk的dataDir配置的目录中的数据。然后重启ZK,使用ZKClient去连接ZK。我这里可以连接到ZK,说明ZK没有问题。

(2)仔细检查我们的配置文件,如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
      xmlns:dubbo="https://code.alibabatech.com/schema/dubbo"
      xmlns="https://www.springframework.org/schema/beans"
      xsi:schemaLocation="https://www.springframework.org/schema/beans
         https://www.springframework.org/schema/beans/spring-beans-4.3.xsd
         https://code.alibabatech.com/schema/dubbo
         https://code.alibabatech.com/schema/dubbo/dubbo.xsd">

   <!-- 应用名称 -->
   <dubbo:application name="demo-consumer"/>

   <!-- 注册中心 -->
   <dubbo:registry protocol="dubbo" address="127.0.0.1:2181" />

   <!-- 服务使用 dubbo 协议调用 -->
   <dubbo:reference id="helloServiceDubbo" interface="com.huangx.dubbo.service.HelloService" protocol="dubbo" />

   <!-- 服务使用 rmi 协议调用 -->
   <dubbo:reference id="helloServiceRMI" interface="com.huangx.dubbo.service.HelloService" protocol="rmi" />

   <!-- 服务使用 hessian 协议调用 -->
   <dubbo:reference id="helloServiceHessian" interface="com.huangx.dubbo.service.HelloService" protocol="hessian" />

</beans>

我们主要查看注册中心的配置,参考 https://dubbo.apache.org/zh-cn/docs/user/references/xml/dubbo-registry.html 地址,该地址是Dubbo官网文档,如下:

protocol<protocol>string可选dubbo服务发现注册中心地址协议,支持dubbo, http, local三种协议,分别表示:dubbo地址、http地址、本地注册中心2.0.0以上版本

根据官网的描述,上面配置没有错误啊。但是就是不能运行,于是参考了 https://dubbo.apache.org/zh-cn/docs/user/references/registry/zookeeper.html 官网关于注册中心配置的教程,发现我的配置存在问题。应该配置如下:

<!-- 注册中心 -->
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />

<!-- 或者 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181" />

这样问题就解决了!!!

总结:自己注册中心的协议配置错误。应该把 dubbo 改为 zookeeper。

疑问?

官网 https://dubbo.apache.org/zh-cn/docs/user/references/xml/dubbo-registry.html 中关于<dubbo:register> 中 protocol 文档描述是不是有问题哦。。。

业精于勤,荒于嬉。——韩愈《进学解》
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
公众号