记录一下dubbo分布式开发,本地测试的方法。常用的有三种:
1.直连。也是最简单的。
服务端:
<dubbo:protocol port="20880" name="dubbo"></dubbo:protocol> <-- 指定端口号 -->
<dubbo:service registry="N/A" ref="customerAppService" interface="cn.ce.cesupport.cma.service.CustomerAppService" /><-- 不需要注册地址 -->
消费者:
<dubbo:reference id="customerAppService" interface="cn.ce.cesupport.cma.service.CustomerAppService" url="dubbo://localhost:20888" check="false" timeout="30000"/><-- 连接本地地址 -->
2.使用全网广播multicast.
服务端:
<dubbo:registry id="customerRe" address="dubbo://224.1.2.3.4:8888"></dubbo:registry><!-- 全网广播,必须224开头-->
<dubbo:service registry="customerRe" ref="customerAppService" interface="cn.ce.cesupport.cma.service.CustomerAppService" />
消费者:
<dubbo:reference id="customerAppService" interface="cn.ce.cesupport.cma.service.CustomerAppService" url="dubbo://224.1.2.3.4:8888" check="false" timeout="30000"/>
3.注册到本地zookeeper.(当然使用redis也是可以的)
f服务端:
<dubbo:registry id="customerRe" address="zookeeper://localhost:2181"></dubbo:registry><!-- zookeeper为注册中心-->
<dubbo:service registry="customerRe" ref="customerAppService" interface="cn.ce.cesupport.cma.service.CustomerAppService" />
消费者:
<dubbo:registry id="userRe" address="zookeeper://127.0.0.1:2181"></dubbo:registry>
<dubbo:reference id="customerAppService" interface="cn.ce.cesupport.cma.service.CustomerAppService" registry="userRe" check="false" timeout="30000"/>