Dubbo Introduction and the combination of spring construction (source stacking send)

Source: Internet
Author: User
Tags zookeeper

Preface

The introduction of Dubbo on the internet has a lot of entry-level instructions, but here, will provide you with Dubbo Introduction, Dubbo combined with the spring project simple construction, as well as provide free download demo source code.

Dubbo's official website is: http://dubbo.io/

Dubbo framework used by the demo source: http://download.csdn.net/detail/fighterandknight/9514559


What is Dubbo? Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation scenarios, as well as SOA service governance scenarios. Simply put, Dubbo is a service framework, if there is no distributed demand, in fact, it is not needed, only in the distributed time, only Dubbo such a distributed service framework needs, and essentially a service call East, plainly is a remote service invocation of the distributed framework
The core part contains:
1. Remote communication: Provides an abstract encapsulation of various NIO frameworks based on long connections, including multiple threading models, serialization, and "request-response" mode of information exchange.
2. Cluster fault tolerance: Provide transparent remote procedure call based on interface method, including multi-protocol support, and cluster support such as soft load balancing, failure fault tolerance, address routing, dynamic configuration, etc.
3. Autodiscover: Based on the Registry directory service, the service consumer can dynamically find the service provider, make the address transparent, so that the service provider can increase or decrease the machine smoothly.


What can Dubbo do? 1. Transparent remote method calls, just like calling a local method, call the remote method, simply configure, without any API intrusion.
2. Soft load balancing and fault tolerant mechanism, can replace F5 and other hardware load balancer in intranet, reduce cost and reduce single point.
3. Service autoenrollment and discovery, no longer required to write dead service provider addresses, the registry queries the IP address of the service provider based on the interface name, and is able to smoothly add or remove service providers.
Dubbo uses a full spring configuration, transparent access to the application, no API intrusion to the application, just load the Dubbo configuration with spring, and Dubbo the spring-based schema extension.

architecture of the DubboDubbothe frame composition is as follows:

Node Role DescriptionProvider: The service provider that exposes the service.
Consumer: Invokes the service consumer of the remote service.
Registry: Registration Center for service Registration and discovery.
Monitor: The monitoring center of the call times of the statistics service and the call time.
Container: The service runs the container.


Call Relationship Description

1) The service container is responsible for starting, loading, and running the service provider.
2) The service provider registers its services with the registry at the time of launch.
3) When the service consumer starts, it subscribes to the registration center for the services it needs.
4) The registry returns the service provider address list to the consumer, and if there is a change, the registry will push the change data to the consumer based on a long connection.
5) Service consumers, from the provider address list, based on the soft load equalization algorithm, select one provider to make the call, if the call fails, then choose another call.
6) service consumers and providers, in memory of the cumulative number of calls and call time, timing every minute to send statistical data to the monitoring center.


Spring combined with Dubbo constructionDubbo Service-side authoringNew Interface
Package Com.znn.provider;public interface Demoservice {string SayHello (string name);}

implementing Interfaces
Package Com.znn.provider;public class Demoserviceimpl implements demoservice{@Overridepublic string SayHello (string Name) {return "Hello Dubbo,hello" + Name;}}

Configure Spring startup files
<?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:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "Http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/ Context         http://www.springframework.org/schema/context/spring-context.xsd        "><import resource=" Dubbo-provider.xml "></import></beans>

Configuring the server-side dubbo-provider.xml file This bean is added to the spring container in the form of adding beans to XML, which we can add to the spring container in the actual development project.
<?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.xs D "> <!--provider application information for compute dependencies--<dubbo:application name=" Hello-world-app "/> <!--use multicast wide Broadcast Registration center Exposure service Address-<!--<dubbo:registry address= "multicast://224.5.6.7:1234"/>-<!--using zookeeper registration Heart Exposure service address--><!--<dubbo:registry address= "zookeeper://115.28.189.59:2181"/>--><dubbo:registry address= "zookeeper://127.0.0.1:2181"/> <!--with Dubbo protocol on 20880 Port exposure service--<dubbo:protocol name= "Dubbo" Port    = "20880"/> <!--declares the service interface that needs to be exposed--<dubbo:service interface= "Com.znn.provider.DemoService" ref= "Demoservice"/> <!--and local beans as a service--&lt ; Bean id= "Demoservice" class= "Com.znn.provider.DemoServiceImpl"/></beans>


Dubbo Client AuthoringSpring Startup file configuration
<?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:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "Http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/ Context         http://www.springframework.org/schema/context/spring-context.xsd        "><import resource=" Dubbo-consumer.xml "/></beans>
Client Dubbo File configuration
<?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.xs D "><!--consumer app name, used to calculate dependencies, not match criteria, and do not--><dubbo:application name=" Consumer-of-helloworld-app "with the provider/> <!--use multicast broadcast registry to expose the Discovery service address--><!--<dubbo:registry address= "multicast://224.5.6.7:1234"/> <dubbo:registry address= "zookeeper://192.168.1.34:2181"/><!--to generate a remote service proxy, which can be used like a local bean demoservice- <dubbo:reference id= "Demoservice" interface= "Com.znn.provider.DemoService"/></beans>
Writing test Dubbo Code
Package Com.znn.consumer;import Org.springframework.context.support.classpathxmlapplicationcontext;import Com.znn.provider.demoservice;public class Consumer {public static void main (string[] args) { Classpathxmlapplicationcontext context = new Classpathxmlapplicationcontext (Classloader.getsystemresource ("") + ": /"+"/dubbo-consumer.xml "), Context.start ();D emoservice demoservice = (demoservice) context.getbean (" DemoService ");      String Hello = Demoservice.sayhello ("World");     System.out.println (hello);}}

Zookeeper StartZookeeper I have uploaded to Csdn, a friend in need can download it by himself http://download.csdn.net/detail/fighterandknight/9514500 Download the Zkserver.cmd file directly after you open the bin directory directly to execute it. you need to replace the port to the Conf file directory below to modify the value of Zoo.cfg ClientPort, specific more detailed other configuration, please refer to the official documentation.
Deploying the Dubbo service sideConfigure the local Dubbo server configuration file, directly deploy the service to Tomcat, if the service successfully started and registration successful zookeeper will appear the following prompt:

Run the Dubbo test caseDirectly executing the Dubbo client Main method, you can see the following results:



SummaryDubbo is still more convenient to use, especially for large-scale project development, as well as large-scale project maintenance, so when it comes to operation and maintenance, it is necessary to combine the use of dubbo-admin, Dubbo-admin exactly how to configure and use, my next blog will provide you with the introduction and related resources to download, please look forward to ~

Dubbo Introduction and the combination of spring construction (source stacking send)

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.