1.不同服务在性能上适用不同协议进行传输
1.1 服务提供者配置
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!-- 提供方应用信息,用于计算依赖关系,这个和client没必要一致 -->
<dubbo:application name="hello-world-app-my" />
<dubbo:registry protocol="zookeeper" address="192.168.0.101:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 用rmi协议在20881端口暴露服务 -->
<dubbo:protocol name="rmi" port="20881" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.test.dubboser.ServiceDemo"
ref="demoService" protocol="dubbo" />
<dubbo:service interface="com.test.dubboser.ServiceDemo2"
ref="demoService2" protocol="rmi" />
<!--和本地bean一样实现服务 -->
<bean id="demoService" class="com.test.dubboser.ServiceImp"/>
<bean id="demoService2" class="com.test.dubboser.ServiceImp2"/>
</beans>
从这些配置我们看到,不同服务使用不同的协议,这种配置方式和其他的配置方式是一样的
1.2 服务消费者配置
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="consumer-of-helloworld-app-my" />
<!-- 使用zookeeper广播注册中心暴露发现服务地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.0.101:2181" />
<dubbo:reference id="demoServicemy" interface="com.test.dubboser.ServiceDemo"/>
<dubbo:reference id="demoServicemy2" interface="com.test.dubboser.ServiceDemo2"/>
</beans>
消费端还是按照正常方式获取服务,只是传递使用的协议不同,底层tcp链接时常不同……
2.同一服务多协议配置
2.1 服务提供者配置
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!-- 提供方应用信息,用于计算依赖关系,这个和client没必要一致 -->
<dubbo:application name="hello-world-app-my" />
<dubbo:registry protocol="zookeeper" address="192.168.0.101:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<dubbo:protocol name="rmi" port="20881" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.test.dubboser.ServiceDemo"
ref="demoService" protocol="dubbo,rmi" />
<!--和本地bean一样实现服务 -->
<bean id="demoService" class="com.test.dubboser.ServiceImp"/>
</beans>
2.2 服务消费者配置
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="consumer-of-helloworld-app-my" />
<!-- 使用zookeeper广播注册中心暴露发现服务地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.0.101:2181" />
<dubbo:reference id="demoServicemy3" interface="com.test.dubboser.ServiceDemo"/>
</beans>
3.不同服务注册到不同的注册中心
3.1 服务提供者配置
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!-- 提供方应用信息,用于计算依赖关系,这个和client没必要一致 -->
<dubbo:application name="hello-world-app-my" />
<!-- 多注册中心配置 -->
<dubbo:registry id="bjregister" protocol="zookeeper" address="192.168.0.101:2181"/>
<dubbo:registry id="shregister" protocol="zookeeper" address="192.168.0.101:2182"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<!--不同服务注册到不同的注册中心 -->
<dubbo:service interface="com.test.dubboser.ServiceDemo"
ref="demoService" registry="bjregister" />
<dubbo:service interface="com.test.dubboser.ServiceDemo2"
ref="demoService2" registry="shregister"/>
<!--和本地bean一样实现服务 -->
<bean id="demoService" class="com.test.dubboser.ServiceImp"/>
<bean id="demoService2" class="com.test.dubboser.ServiceImp2"/>
</beans>
3.2 服务消费者配置文件
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="consumer-of-helloworld-app-my" />
<!-- 使用zookeeper广播注册中心暴露发现服务地址 -->
<!--向两个注册中心订阅 -->
<dubbo:registry protocol="zookeeper" address="192.168.0.101:2181"/>
<dubbo:registry protocol="zookeeper" address="192.168.0.101:2182"/>
<!--获取服务 -->
<dubbo:reference id="demoServicemy" interface="com.test.dubboser.ServiceDemo"/>
<dubbo:reference id="demoServicemy2" interface="com.test.dubboser.ServiceDemo2"/>
</beans>