Dubbo的注册中心 官方推荐zookeeper

Dubbo的注册中心 

本文使用zookeeeper

1.原理简介

主要用于不同服务器间通讯;

a.可进行无URL访问(开发) 需设置<dubbo:registry address="N/A"/>

b.可进行有URL访问(实际) 需设置<dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/> 


 

 提供方:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/task
    http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://code.alibabatech.com/schema/dubbo        
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<!-- Dubbo提供方 -->
<!-- 1:名称  计算机 区别 唯一 -->
<dubbo:application name="babasport-service-product"/>
<!-- 2:设置注册中心  地址  zookeeper在哪里  redis ... -->
<!-- <dubbo:registry address="192.168.200.128:2181,192.168.200.129:2181,192.168.200.130:2181" protocol="zookeeper"/> -->
<!-- <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/> -->
<dubbo:registry address="N/A"/>
<!-- 3:dubbo://192.168.39.80:20880  默认  设置提供服务的端口号 -->
<dubbo:protocol port="20880" name="dubbo"/>
<!-- 4: 暴露实现类-->
<dubbo:service interface="cn.itcast.core.service.TestTbService" ref="testTbService"/>
</beans>

消费方:

<!-- Dubbo消费方 -->
<!-- 1:名称  计算机 区别 唯一 -->
<dubbo:application name="babasport-console"/>
<!-- 2:设置注册中心  地址  zookeeper在哪里  redis ... -->
<!-- <dubbo:registry address="192.168.200.128:2181,192.168.200.129:2181,192.168.200.130:2181" protocol="zookeeper"/> -->
<!-- <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/> -->
<dubbo:registry address="N/A" check="false"/>
<!-- 4: 调用此接口对应的实现类  单位毫秒-->
<dubbo:reference interface="cn.itcast.core.service.TestTbService" id="testTbService"
url="dubbo://127.0.0.1:20880" 
/>
<!-- 全局设置 -->
<dubbo:consumer timeout="600000" check="false"/>

</beans>

 2.注意事项:

a.一个服务器对应一个端口,如果访问另一个服务器,则要配置提供方,且端口号20880要变的不一致;

b.如果采用无URL通讯,则消费方也需配置<dubbo:registry address="N/A" check="false"/>

c.且消费方需全局配置时间,否则通讯失败<dubbo:consumer timeout="600000" check="false"/>

d.Dubbo消费方及提供方传递的参数必须实现序列化接口

 

 

 

 

 


猜你喜欢

转载自blog.csdn.net/hxb_hexiaobo/article/details/77198254