Now that you’ve learned about the general use of Dubbo, let’s look at some special or real-world configuration examples that use Dubbo.

If an interface has more than one implementation, you can use group to distinguish it

1. Service provider configuration

[html]
view plain
copy

  1. <beans xmlns=”http://www.springframework.org/schema/beans”
  2. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
  3. xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”
  4. xsi:schemaLocation=”http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://code.alibabatech.com/schema/dubbo
  7. http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  8. “>
  9. <! — Provider application information, used to calculate dependencies, does not need to be consistent with client –>
  10. <dubbo:application name=”hello-world-app-my” />
  11. <! Expose the service address using the ZooKeeper broadcast registry –>
  12. “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
  13. <! Expose service on port 20880 with dubbo
  14. <dubbo:protocol name=”dubbo” port=”20880″ />
  15. <! Declare the service interface to be exposed –>
  16. <dubbo:service group=”1″ interface=”com.test.dubboser.ServiceDemo”
  17. ref=”demoService” />
  18. <dubbo:service group=”2″ interface=”com.test.dubboser.ServiceDemo”
  19. ref=”demoService2″ />
  20. <! Implement the service as a local bean
  21. <bean id=”demoService” class=”com.test.dubboser.ServiceImp”/>
  22. <bean id=”demoService2″ class=”com.test.dubboser.ServiceImp2″/>
  23. </beans>

All other configurations are the same, and the exposed service interface distinguishes the two implementation classes by group

2. Service consumer configuration

[html]
view plain
copy

  1. <beans xmlns=”http://www.springframework.org/schema/beans”
  2. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
  3. xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”
  4. xsi:schemaLocation=”http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://code.alibabatech.com/schema/dubbo
  7. http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  8. “>
  9. <! — Consumer application name, used to calculate dependencies, not matching conditions, not the same as provider –>
  10. <dubbo:application name=”consumer-of-helloworld-app-my” />
  11. <! Expose discovery service address using zooKeeper broadcast registry –>
  12. “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
  13. <! Create a remote service proxy that can use demoService as a local bean –>
  14. <dubbo:reference id=”demoServicemy” group=”1″ interface=”com.test.dubboser.ServiceDemo” />
  15. <dubbo:reference id=”demoServicemy2″ group=”2″ interface=”com.test.dubboser.ServiceDemo” />
  16. </beans>

Again, group is used here

2. When an interface implementation has incompatible upgrades, it can use the version number to transition. Services with different version numbers do not reference each other

1. Service provider configuration

[html]
view plain
copy

  1. <beans xmlns=”http://www.springframework.org/schema/beans”
  2. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
  3. xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”
  4. xsi:schemaLocation=”http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://code.alibabatech.com/schema/dubbo
  7. http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  8. “>
  9. <! — Provider application information, used to calculate dependencies, does not need to be consistent with client –>
  10. <dubbo:application name=”hello-world-app-my” />
  11. <! Expose the service address using the ZooKeeper broadcast registry –>
  12. “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
  13. <! Expose service on port 20880 with dubbo
  14. <dubbo:protocol name=”dubbo” port=”20880″ />
  15. <! Declare the service interface to be exposed –>
  16. <dubbo:service version=”1″ interface=”com.test.dubboser.ServiceDemo”
  17. ref=”demoService” />
  18. <dubbo:service version=”2″ interface=”com.test.dubboser.ServiceDemo”
  19. ref=”demoService2″ />
  20. <! Implement the service as a local bean
  21. <bean id=”demoService” class=”com.test.dubboser.ServiceImp”/>
  22. <bean id=”demoService2″ class=”com.test.dubboser.ServiceImp2″/>
  23. </beans>

Add version to differentiate

2. Service consumer configuration

[html]
view plain
copy

  1. <beans xmlns=”http://www.springframework.org/schema/beans”
  2. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
  3. xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”
  4. xsi:schemaLocation=”http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://code.alibabatech.com/schema/dubbo
  7. http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  8. “>
  9. <! — Consumer application name, used to calculate dependencies, not matching conditions, not the same as provider –>
  10. <dubbo:application name=”consumer-of-helloworld-app-my” />
  11. <! Expose discovery service address using zooKeeper broadcast registry –>
  12. “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
  13. <! Create a remote service proxy that can use demoService as a local bean –>
  14. <dubbo:reference id=”demoServicemy” version=”1″ interface=”com.test.dubboser.ServiceDemo” />
  15. <dubbo:reference id=”demoServicemy2″ version=”2″ interface=”com.test.dubboser.ServiceDemo” />
  16. </beans>

On the service consumer side, use version to differentiate

Classic introduction:

Source structure




Willing to understand the framework technology or source code of friends directly ask to exchange technology: 2042849237

Some distributed solutions, friends who are willing to understand can find our team to discuss

More detailed source code reference source: minglisoft.cn/technology

Dubbo + SpringMVC + Mybatis + Ehcache + Redis J2ee distributed architecture, restful, Kafka, Shiro

Dubbo + SpringMVC + Mybatis + EhCache + Redis J2ee distributed architecture, restful, Shiro