1. 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 requirements, in fact, is not needed, only in the distributed time, only Dubbo such a distributed service framework requirements, and essentially a service invocation of the east, the white is a remote service invocation of the distributed framework (farewell to the Web WSDL in service mode, to be registered on Dubbo in the manner of server and consumer
Its core section contains:
1. Remote communications: Provides an abstract encapsulation of a variety of long connected NIO frameworks, including multiple threading models, serialization, and "request-response" mode of information interchange.
2. Cluster fault tolerance: Provides transparent remote procedure calls based on interface methods, including multi-protocol support, and cluster support such as soft load balancing, failure fault tolerance, address routing, dynamic configuration, etc.
3. Automatic discovery: 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 smooth increase or reduce the machine. 2. What Dubbo can do.
1. A transparent remote method call, called a remote method like a local method, requires a simple configuration with no 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 automatic registration and discovery, no longer need to write dead service provider address, registry based on Interface name Query service provider's IP address, and can smooth add or remove service providers.
Dubbo uses a full spring configuration, transparent access applications, no API intrusion on the application, just use spring to load the Dubbo configuration, Dubbo load based on the schema extension of spring.
Before using the Web service, I wanted to test the interface to perform functional or performance testing through SOAPUI or LR in the form of analog messages. But now using Dubbo, the interface can not directly interact, I tried to simulate consumer address test, the result is offensive, and then use JMeter through JUnit test, but still need to go to the Dubbo to register, if not to provide the premise of the source code, this test case is not easy to write AH ....
3. The structure of the Dubbo Dubbo frame is shown as follows:
Node role Description:
Provider: 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 time reconciliation call times for statistical services.
Container: Service Run container.
I think it's very good, the role is distinct, you can determine whether the service is normal according to the status of each node role. Call Relationship Description:
0 The service container is responsible for starting, loading, and running the service provider. 1. The service provider registers its own services with the registry at the time of commencement. 2. When starting, the service consumer subscribes to the registry for the services it needs. 3. The registry returns the service provider address list to the consumer, and if so, the registry will push the change data to the consumer based on the long connection. 4. Service consumers, from the provider address list, based on the soft load equalization algorithm, select a provider to invoke, if the call fails, then select another call. 5. Service consumers and providers, in the memory of the cumulative number of calls and call time, timed every minute to send statistical data to the monitoring center.
Dubbo fault tolerance is obvious, performance has not yet to be measured, our system a page need to drop 5 interface, would like to suggest a cache, but the business relationship can not be adopted, but also need to study the performance of the Dubbo problem. 4. Dubbo use method.
Dubbo uses a full spring configuration, transparent access applications, no API intrusion on the application, just use spring to load the Dubbo configuration, Dubbo load based on the schema extension of spring. If you do not want to use the spring configuration and want to invoke it through the API (not recommended)
Let's take a look at how the Spring configuration works: Service providers:
1. Download Zookeeper Registration Center, download the address: http://www.apache.org/dyn/closer.cgi/zookeeper/download after decompression can be, into the D:\apach-zookeeper-3.4.5\bin,
Double-click Zkserver.cmd to start the Registration center service. 2. Define the Service interface: (this interface needs to be packaged separately, shared between the service provider and the consumer)
The following example is good, write very detailed can do a model. Package com.unj.dubbotest.provider; Import java.util.List; Public interface Demoservice {string SayHello (string name); Public List getusers (); }
The
implements the interface on the service provider: (hides the implementation for the service consumer)
package com.unj.dubbotest.provider; import java.util.arraylist; import java.util.linkedlist; import java.util.list; public class demoserviceimpl implements demoservice{ public string sayhello (string name) { return "hello " + name; } public list getusers () { List List = new arraylist (); user u1 = new user (); U1.setname ("Jack"); u1.setage; u1.setsex ("male"); User u2 = New user (); u2.setname ("Tom"); u2.setage (; ) u2.setsex ("female"); user u3 = new user (); u3.setname ("Rose"); u3.setage (; ) u3. Setsex ("female"); list.add (U1); list.add (U2); list.add (U3); return list; } }
Declaring exposure services with spring 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.xsd "> <!-- Concrete implementation bean --> <bean id= " Demoservice " class= "Com.unj.dubbotest.provider.DemoServiceImpl" /> <!-- Provider application information, for computing dependencies --> <dubbo : Application name= "Xixi_provider" /> <!-- Use multicast broadcast registry to expose service address <dubbo:registry address= "multicast://224.5.6.7:1234" />--> <! -- use zookeeper Registry to expose service address --> <dubbo:registry address= " zookeeper://127.0.0.1:2181 " /> <!- - service --> <dubbo:protocol name= in Port 20880 with Dubbo Protocol Dubbo " port=" 20880 /> <!-- statement required to expose the service to receiveMouth --> <dubbo:service interface= " Com.unj.dubbotest.provider.DemoService " ref=" Demoservice " /> </beans> Load Spring configuration, start service: package com.unj.dubbotest.provider; import org.springframework.context.support.classpathxmlapplicationcontext; public class provider { public Static void main (String[] args) throws Exception { ClassPathXmlApplicationContext context = new Classpathxmlapplicationcontext (new string[] {"Applicationcontext.xml"}); context.start (); system.in.read (); //&nBSP: To ensure that the service is always open, use the blocking of the input stream to simulate } }
Service Consumer:
Applicationcontext-dubbo.xml to register their own needs to call the interface, I just started testing when the need for a lot of interfaces, so write this file is full, and later familiar with the interface by business type separate, wrote n multiple Applicationcontext-dubbo-***.xml is more concise than the ".
1. Referencing remote services via spring 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.xsd "> <!-- Consumer application name, used to compute dependencies, not matching criteria, not the same as provider --> <dubbo:application name= "Hehe_consumer" /> <!-- using zookeeper registry to expose service address --> <!-- <dubbo:registry address= "multicast://224.5.6.7:1234" / > --> <dubbo:registry address= "zookeeper:// 127.0.0.1:2181 " /> <!-- Generate remote service proxy, You can use the demoservice --> <dubbo:reference id= as you would with a local bean. Demoservice " interface=" Com.unj.dubbotest.provider.DemoService " /> </beans>
2. Load the spring configuration and invoke the remote service: package com.alibaba.dubbo.demo.pp; import java.util.list ; import org.springframework.context.support.classpathxmlapplicationcontext; import com.unj.dubbotest.provider.demoservice; Public class Consumer { public static void main ( String[] args) throws Exception { classpathxmlapplicationcontext context = new classpathxmlapplicationcontext ( new String[] { "Applicationcontext.xml"  }); context.start (); demoservice demoservice = (Demoservice) context.getbean ("Demoservice"); // string hello = demoservice.sayhello ("Tom"); // ִ system.out.println (Hello); // // list list = demoservice.getusers (); if (List != null && list.size () > 0) { for (int I = 0; i < list.size () i++) { system.out.println (List.get (i)); } } // system.out.println ( Demoservice.hehe ()); system.in.read (); } }
The result of the call is:
Dubbo Admin Page:
This management page also needs to deploy an environment, at first I thought it was Dubbo, looking for a half-day did not find ....
Application page:
Provider page:
Consumer page:
Service page:
Test is successful, I think as long as to see whether the state is normal, OK ....
Case code Download: http://download.csdn.net/detail/yiyu1/7116319