dubbo 支持多注册中心
有个场景就是自己的xxx-RPC工程和xxx-web工程. web工程依赖多个RPC微服务,包含自己参与的xxx-RPC工程。 那我们就可以替换测试环境的xxx-rpc,而使用自己本地的rpc.
很简单:
- RPC项目 和 web项目都引入本地的注册中心,使用id开区分
<dubbo:registry id="dubbo" address="" check="false" client="" file="false" subscribe="true" username=" password="" />
<!-- 本地注册中心-->
<dubbo:registry id="local" address="zookeeper://127.0.0.1:2181" check="false" client="" file="false" subscribe="true" username="" password="" />
2. RPC项目暴露服务使用上面的注册中心,通过 registry来区分
<!-- 要暴露的服务接口 -->
<dubbo:service registry="local" interface="xx.xx.xxxx" ref="xxxx" cluster="failover" loadbalance="leastactive" />
<bean id="xxxx" class="xxxImpl" />
<!-- 要引用的服务接口 -->
<dubbo:reference registry="dubbo" id="omsRPCService" interface="com.huawei.vmall.oms.dubbo.api.OMSInterfaceForBalanceKey"
check="false" />
- web工程引用
<dubbo:registry id="server111" address="${dubbo.registry.address}" check="false" client="vmallCurator" file="false" subscribe="true"
username="${xxx}" password="${xxx}" />
<dubbo:registry id="local222" address="zookeeper://127.0.0.1:2181" check="false" client="vmallCurator" file="false" subscribe="true"
username="" password="" />
<dubbo:reference registry="local222" id="xxxx" interface="xxxx.xxxx222" retries="0" timeout="10000" check="false" />
<dubbo:reference registry="server111" id="xxxx" interface="xxxx.xxxx111" retries="0" timeout="10000" check="false" />
然后web工程可以调用到本地工程了。(svn、git不要提交这个修改后的代码到服务器) 当然,web 直接依赖rpc工程也可以实现上述联调。