Java projects using Dubbo combat

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.