Dubbo无法访问远程无法访问远程Zookeeper已注册服务的问题解决方案已注册服务的问题解决方案
今天小编就为大家分享一篇关于Dubbo无法访问远程Zookeeper已注册服务的问题解决方案,小编觉得内容挺不
错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
背景背景
使用Dubbo的时候发现当Zookeeper、Dubbo-admin、生产者和消费者都在内网中的时候,生产者的生产和消费是没有问题
的,但是当它Zookeeper、生产者放到远程服务器上,然后消费者在访问消费就出现了无法找到找到服务的问题。
内网环境使用情况内网环境使用情况
上述的图是在同一个内网中,使用的代码如下:
1、生产者配置、生产者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="Jhd_Security" owner="allen.xu" organization="MyJhd"/>
<dubbo:registry address="zookeeper://172.16.61.101:2181" timeout="500000" group="JhdGroup" id="myjhd_id"/>
<!-- 暴露出去的接口-->
<bean id="dubboDemoFacade" class="com.dubbo.demo.facade.impl.DubboDemoFacade"/>
<dubbo:service
ref="dubboDemoFacade"
interface="com.dubbo.demo.facade.IDubboDemoFacade"
version="1.0.0"
cluster="failfast"
executes="10"
timeout="500000"
registry="myjhd_id">
</dubbo:service>
</beans>
2、消费者配置、消费者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="consumer-of-sayHello-app" owner="allen.xu" organization="MyJhd"/>
<dubbo:registry address="zookeeper://172.16.61.101:2181" timeout="500000" group="JhdGroup" id="myjhd_id"/>
<dubbo:reference id="dubboDemoFacade"
interface="com.dubbo.demo.facade.IDubboDemoFacade"
version="1.0.0"
cluster="failfast"
timeout="500000"
registry="myjhd_id"/>
</beans>