You should be aware of Dubbo

What is dubbo

Dubbo Alibaba is open distributed service framework, which is the biggest feature of the architecture in a layered manner, this embodiment can make use of solutions of the coupling between the respective layers (or maximum loosely coupled). From the point of view of the service model, Dubbo uses a very simple model, either the provider of service, either consumer consumer services, so this can be based on abstract service provider (Provider) and consumer services (Consumer) two roles. About registry, protocol support, service monitoring, etc., described later in this description. Webservice also a service framework, but the webservice is not distributed service framework, he requires a combination of F5 load balancing. Therefore, dubbo in addition to provide services, but also can achieve a soft load balancing. It also provides two functions Monitor control center and call center. Both are optional, configured separately.

Dubbo is the core framework Alibaba SOA service governance program, providing high performance and transparency of RPC remote service call programs, services and SOA governance program. The core section includes:

Remote Communication : providing a variety of frame based NIO package length abstract connection model comprises a plurality of threads, serialization, and - information exchange "request-response" mode.
Fault-tolerant cluster : providing a transparent interface method is based on remote procedure calls, including multi-protocol support, as well as soft load balancing, fault tolerance failure, address routing, dynamic configuration and other cluster support.
Automatic discovery : a registry-based directory service, the service can only consume dynamic lookup service provider, the address is transparent, so that the service provider may increase or decrease smooth machine.

So, what do Dubbo?
  • Transparent remote method invocation, the same as calling a local method call remote methods, only a simple configuration, without any intrusion API.
  • Soft load balancing and fault tolerance mechanisms, including the network can replace F5 hardware load balancer, lower costs, reduce single point.
  • Automatic registration and service discovery, no longer need to write the dead service provider address, IP address registry based query interface name service provider, and can be smoothly add or remove services provider.

Dubbo Local JAR package deployment and installation

After Dubbox jar package is not deployed to the Maven's central repository, you can look in the Maven central repository in Dubbo to the final version is 2.5.3, Ali Baba disbanded Dubbo team continues to maintain this project consists of Dangdang, and renamed as Dubbox, coordinates unchanged, version changes, but did not submit to the central repository.
We now need to manually install Dubbox jar package to my local warehouse.
First dubbo-2.8.4.jar package into d: \ folder name, and then enter the command

mvn install:install-file -Dfile=d:\文件夹名\dubbo-2.8.4.jar -DgroupId=com.alibaba -DartifactId=dubbo -Dversion=2.8.4 -Dpackaging=jar

Offline Configuration Constraints (code hints)

http://code.alibabatech.com/schema/dubbo/dubbo.xsd

What is Dubbox

Dubbox About
Dubbox is a distributed service framework, its predecessor is an open source project Alibaba Dubbo, is the use of domestic electricity providers and Internet projects, the late Ali Baba stopped the maintenance of the project, Dangdang will be optimized on the basis of Dubbo, and continue to maintain, in order to distinguish the original Dubbo, so name it Dubbox.

Distributed Services Framework:

  • High performance and transparency of RPC remote service call scheme
  • SOA service governance plan
  • Reactor Model Apache MINA frame based communication framework, a long connection based on tcp

Dubbo default protocol uses a single long connection and NIO asynchronous communications, suitable for small amount of data concurrent service call, and when the number of machines is much greater than the number of consumer service providers Machine
analyze the source code, the basic principle is as follows:

  1. client thread calls a remote interface, generate a unique ID (such as a random string, the UUID, etc.), using AtomicLong Dubbo accumulated number from 0
  2. The packing method invocation information (e.g. call interface name, method name, list of parameter values, etc.), and the processing result of the callback callback object, all packaged together to form a target object
  3. Specialized storage information to call the global ConcurrentHashMap inside put (ID, object)
  4. The package ID and the method call information into a target connRequest, sent using IoSession.write (connRequest) Asynchronous
  5. The current thread and then use the get callback () method of trying to get the results of remote returned in get () inside, using synchronized to acquire the lock callback object callback, and then check to make sure already acquired results, if not, then call the callback wait () method to release the lock on the callback, so that the current thread in a wait state.
  6. After the server receives the request and process the results (including the results of this in front of ID, i.e. return) to the client, the client listening socket special message received from the message thread connection, analysis results, taking the ID , then from the front inside ConcurrentHashMap get (ID), to find callback, the result of a call to set the callback object.
  7. Listening thread then use synchronized acquiring the lock callback object callback (since earlier been called wait (), the thread has released the lock callback of a), and then notifyAll (), continue to get (callback wake-up thread in front of a wait state () the method continues able to get the result of the call), thus, the entire process is completed.

The current thread how it "pause", and so after the results came back, again after performing?
A: Mr. into an object obj, store them in a global map was put (ID, obj), then get synchronized obj lock, then call obj.wait () so that the current thread in a wait state (waitSet), then another message listening thread to wait until after the service end result, and then map.get (ID) found obj, then get synchronized obj lock, then call obj.notifyAll () wake up in front of the thread in a wait state.

As previously mentioned, Socket communication is a full duplex manner, if multiple threads simultaneously remote method invocation, then there will be many established messaging sent on both socket connection between the client server, but also before and after the order may be a mess, after server processed the results, the results send a message to the client, client received a lot of messages, how do you know which message is the result of which thread originally called?
A: Use an ID, let it unique, then passed to the server, then the server and return back, so you know which thread a result of the original.
Here Insert Picture Description
Service side: service layer (exposed interfaces), consumer: controller layer (remote injection)
Logical Explanation : The service side landlord has a similar rental, consumer similar to the tenant rent, the landlord rent the house to find the intermediary (registry), told the agency the size of their house address and other information, rental tenants looking for an intermediary, the intermediary will request information in accordance with the tenant, the landlord found

Published 32 original articles · won praise 53 · views 2478

Guess you like

Origin blog.csdn.net/qq_41714882/article/details/103956833