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
view plain
copy
- <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
- “>
- <! — Provider application information, used to calculate dependencies, does not need to be consistent with client –>
- <dubbo:application name=”hello-world-app-my” />
- <! Expose the service address using the ZooKeeper broadcast registry –>
- “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
- <! Expose service on port 20880 with dubbo
- <dubbo:protocol name=”dubbo” port=”20880″ />
- <! Declare the service interface to be exposed –>
- <dubbo:service group=”1″ interface=”com.test.dubboser.ServiceDemo”
- ref=”demoService” />
- <dubbo:service group=”2″ interface=”com.test.dubboser.ServiceDemo”
- ref=”demoService2″ />
- <! Implement the service as a local bean
- <bean id=”demoService” class=”com.test.dubboser.ServiceImp”/>
- <bean id=”demoService2″ class=”com.test.dubboser.ServiceImp2″/>
- </beans>
All other configurations are the same, and the exposed service interface distinguishes the two implementation classes by group
2. Service consumer configuration
view plain
copy
- <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
- “>
- <! — Consumer application name, used to calculate dependencies, not matching conditions, not the same as provider –>
- <dubbo:application name=”consumer-of-helloworld-app-my” />
- <! Expose discovery service address using zooKeeper broadcast registry –>
- “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
- <! Create a remote service proxy that can use demoService as a local bean –>
- <dubbo:reference id=”demoServicemy” group=”1″ interface=”com.test.dubboser.ServiceDemo” />
- <dubbo:reference id=”demoServicemy2″ group=”2″ interface=”com.test.dubboser.ServiceDemo” />
- </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
view plain
copy
- <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
- “>
- <! — Provider application information, used to calculate dependencies, does not need to be consistent with client –>
- <dubbo:application name=”hello-world-app-my” />
- <! Expose the service address using the ZooKeeper broadcast registry –>
- “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
- <! Expose service on port 20880 with dubbo
- <dubbo:protocol name=”dubbo” port=”20880″ />
- <! Declare the service interface to be exposed –>
- <dubbo:service version=”1″ interface=”com.test.dubboser.ServiceDemo”
- ref=”demoService” />
- <dubbo:service version=”2″ interface=”com.test.dubboser.ServiceDemo”
- ref=”demoService2″ />
- <! Implement the service as a local bean
- <bean id=”demoService” class=”com.test.dubboser.ServiceImp”/>
- <bean id=”demoService2″ class=”com.test.dubboser.ServiceImp2″/>
- </beans>
Add version to differentiate
2. Service consumer configuration
view plain
copy
- <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
- “>
- <! — Consumer application name, used to calculate dependencies, not matching conditions, not the same as provider –>
- <dubbo:application name=”consumer-of-helloworld-app-my” />
- <! Expose discovery service address using zooKeeper broadcast registry –>
- “Dubbo: registry protocol =” zookeeper “address =” 192.168.0.107:2181 “/ >
- <! Create a remote service proxy that can use demoService as a local bean –>
- <dubbo:reference id=”demoServicemy” version=”1″ interface=”com.test.dubboser.ServiceDemo” />
- <dubbo:reference id=”demoServicemy2″ version=”2″ interface=”com.test.dubboser.ServiceDemo” />
- </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