<dubbo:application name="producer"/>
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>
<dubbo:protocol name="dubbo" port="20882" />
<dubbo:service interface="com.dgc.learn.service.UserService" ref="userServiceImpl" />
<dubbo:reference interface="com.dgc.learn.service.UserService" id="userService" />
由于网络原因,可能会出现不确定的中间状态(超时),为防止因超时引起的阻塞,需设置超时时间
消费端
<dubbo:consumer timeout="5000" />
<dubbo:reference interface="com.foo.BarService" timeout="2000">
<dubbo:method name="sayHello" timeout="3000" />
</dubbo:reference>
服务端
<dubbo:provider timeout="5000"/>
<dubbo:provider interface="com.foo.BarService" timeout="2000">
<dubbo:method name="sayHello" timeout="3000" />
</dubbo:provider>
当出现失败,会自动重试其它服务器,重试次数(不含第一次)
<dubbo:service retries="2"/>
<dubbo:reference retries="2"/>
注意:两端配置其一即可!
方便接口升级,不影响老版本接口,对接口增加版本号
服务端:
<dubbo:service version="1.0.0"/>
消费端:
<dubbo:reference version="1.0.0"/>
注意:两者之间只要version号相同时才可以调用!!!
<dubbo:service interface="..." loadbalance="roundrobin"/>
<dubbo:reference cheack="true">
<dubbo:consumer cheack="true">
<dubbo:registry cheack="true">
<dubbo:registry id="one" protocol="zookeeper" address="127.0.0.1:2181"/>
<dubbo:registry id="two" protocol="zookeeper" address="127.0.0.2:2181"/>
指定注册中心<dubbo:service interface="com.dgc.learn.service.UserService" ref="userServiceImpl" registry="one"/>
<dubbo:service async="true">
<dubbo:registry register="false">
<dubbo registry subscribe="false">
局部覆盖外部,消费端覆盖提供端<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="提供端服务名称" default="true"/>
<dubbo:registry id="register" address="注册地址1" file="注册接口缓存的服务器目录"/>
<dubbo:registry id="auth" address="注册地址2" file="注册接口缓存的服务器目录"/>
<dubbo:protocol name="通信规则名称" port="通信端口" threads="线程数量" payload="接口传输流量上限"/>
<!--配置链接不到注册中心报错-->
<dubbo:registry cheack="true">
<!-- 提供服务
retries:重试次数
timeout:超时时间
registry:注册地址
async:是否支持结果异步
version:接口版本
-->
<dubbo:service interface="cn.com.dgc.service.WebServiceBiz"
ref="webServiceBiz" retries="0" timeout="60000" registry="register" async="false"
version="1.0.0"
/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="消费端服务名称" default="true"/>
<dubbo:registry id="register" address="注册地址1"/>
<dubbo:registry id="logger" address="注册地址2"/>
<dubbo:protocol name="通信规则名称"/>
<!--消费接口-->
<dubbo:reference registry="register"interface="cn.com.dgc.service.WebServiceBiz"
id="webServiceBiz" check="false" timeout="60000"/>
</beans>