The last article talked about how to build a Zookeeper+dubbo platform, but the ultimate goal of the platform is to apply in the project, next I will say how to apply in Java code.
Dubbo, as an RPC management tool, is used to manage the situation of the consumer of the service invoking the service provider.
In practical applications, you can build a stand-alone Java project that contains all of the interfaces defined, not implemented, and then lets service providers and users rely on the project, provider is responsible for implementing the interface, and the customer simply calls the method defined by the interface directly , the code for this public project is no longer in detail.
Service provider configuration: (New configuration file Spring-dubbo.xml)
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:context= " Http://www.springframework.org/schema/context "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/
Spring-beans.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http:// WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd HTtp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <dubbo: Application Name= "Mywebappname"/> <!--set the name of the application--> <dubbo:registry address= "zookeeper://127.0.0.1:2181? backup=127.0.0.2:2181 "/> <!--Configure the Zookeeper server to which this project points--> <dubbo:protocol name=" Dubbo "port=" 20888 "/> <!--Configure the Dubbo protocol Port--> <bean id= "Usermanualinterfaceimpl" Com.tonson.dubbo.interface.impl.UserManualInterfaceImpl "/> <!--Interface implementation class--> <dubbo:service interface=" Com.tonson.dubbo.interface.UserManualInterface "ref=" Usermanualinterfaceimpl "timeout=" 3000 "/> <!-- Declarations specify which interfaces are provided by the service--> </beans>
Service Caller's configuration: (New profile Spring-dubbo.xml)
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:context= " Http://www.springframework.org/schema/context "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/
Spring-beans.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http:// WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd HTtp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <dubbo: Application Name= "Mywebappname"/> <!--set the name of the application--> <dubbo:registry address= "zookeeper://127.0.0.1:2181? backup=127.0.0.2:2181 "/> <!--Configure the Zookeeper server to which this project points--> <dubbo:protocol name=" Dubbo "port=" 20888 "/> <!--Configure the Dubbo protocol Port--> <dubbo:reference interface= "Com.tonson.dubbo.interface.UserManualInterface" Usermanualinterface "check= false"/><!--define the bean--> to use the interface </beans>
This has already connected the service's provider and customer through the Dubbo, in Java coding, as well as the normal spring dependency injection.