服务提供者和服务消费者在同一个应用中
把application信息放在总dubbo配置文件中,并引用provider和consumer的配置文件
dubbo-demo.xml
<dubbo:application name="dubbo_demo" owner="kelly.li" organization="tcdev" /> <import resource="dubbo-demo-provider.xml" /> <import resource="dubbo-demo-consumer.xml" />
provider中不配置application信息
dubbo-demo-provider.xml
<context:property-placeholder location="classpath:dubbo_provider.properties" ignore-unresolvable="true" /> <dubbo:registry protocol ="zookeeper" address="各环境zk地址" group="/demo/group/default" /> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:provider> <dubbo:parameter key="qloglevel" value="10" /> <dubbo:parameter key="server" value="netty4" /> <!--因为考虑client不会同时升级,兼容netty3,不然会出异常--> <dubbo:parameter key="client" value="netty" /> </dubbo:provider> <dubbo:service interface="qunar.tc.dubbo.demo.api.HelloService" ref="helloService" version="1.0" timeout="3000"/> <bean id="helloService" ></bean>
consumer中不配置application信息
dubbo-demo-consumer.xml
<context:property-placeholder location="classpath:dubbo_consumer.properties" ignore-unresolvable="true" /> <dubbo:registry protocol="zookeeper" address="各环境zk地址" group="/demo/group/default" /> <dubbo:consumer> <dubbo:parameter key="qloglevel" value="10" /> <dubbo:parameter key="client" value="netty4" /> </dubbo:consumer> <dubbo:reference id="helloService" interface="qunar.tc.dubbo.demo.api.HelloService" version="1.0" check="false" /> <bean id="helloAction" class="qunar.tc.demo.consumer.HelloAction" ></ bean>
Dubbo直连
在开发及测试环境下,经常需要绕过注册中心,只测试指定服务提供者,这时候可能需要点对点直连,点对点直联方式,将以服务接口为单位,忽略注册中心的提供者列表
在<dubbo:reference>中配置url指向提供者,多个地址用分号隔开
dubbo-demo-consumer.xml
<context:property-placeholder location="classpath:dubbo.properties" ignore-unresolvable="true" /> <dubbo:reference id="helloService" interface="qunar.tc.dubbo.demo.api.HelloService" version="1.0" check="false" url="dubbo://服务ip地址:服务port" /> <bean id="helloAction" class="qunar.tc.demo.consumer.HelloAction"></bean>
服务分组 :一个服务接口多种实现
delay Q中有这样一个应用场景,delay server和broker server 都实现BrokerMessageService接收消息。delay Q需要提供一个BrokerMessageService从client端接收消息,然后引用broker server的同一接口发送消息。服务分组做法采用不同的zookeeper注册中心。配置如下:
<dubbo:application name="qmq-delay" ></dubbo:application> <dubbo:registry id="broker" address="各环境zk地址" protocol="zookeeper" group="/qmq/broker/default" /> <dubbo:registry id="delay" address="各环境zk地址" protocol="zookeeper" group="/qmq/delay/default" /> <dubbo:protocol name="dubbo" port="20880"/> <!-- delay server 接收消息服务 --> <dubbo:service id="delayMessageService" interface="qunar.tc.qmq.service.BrokerMessageService" ref="scheduleMessageService" registry="delay" version="1.0" cluster="failfast" /> <!--broker server 接收消息服务 --> <dubbo:reference id="messageService" interface="qunar.tc.qmq.service.BrokerMessageService" registry="broker" version="1.0" scope="remote" />