1、采用zookeeper作为注册中心
<?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-2.5.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 声明应用名称 --> <dubbo:application name="platform-service" organization="test"/> <!--注册中心为zk --> <dubbo:registry protocol="zookeeper" address="zk.test.com:2181" file="./.dubbo-platform"/> <!--把服务暴露在dubbo的21884端口--> <dubbo:protocol name="dubbo" port="21884" serialization="hessian2" /> <dubbo:protocol name="rest" port="8888"/> </beans>
2,无注册中心,采用直连的方式
<dubbo:registry protocol="zookeeper" address="N/A" file="./.dubbo-platform"/>
直连的方式使用时,消费者引用的url要配置成本地
<dubbo:reference id="userService" url="dubbo://127.0.0.1:21884" interface="com.test.platform.api.UserService" check="true"/>
3,通过广播的方式
<dubbo:registry address="multicast://xxx.5x.x.x:1234?unicast=false" />
注意组播地址段: 224.0.0.0 - 239.255.255.255