Preliminary knowledge of Distributed service management framework-dubbo

Source: Internet
Author: User

Welcome to Join Dubbo Group: 259566260

Dubbo is an open source distributed service management framework under Ali. It is generated because of the distributed generation. Here are a few points to share my preliminary understanding of Dubbo. Learn how to use and basic design ideas with Dubbo's official documentation. Http://alibaba.github.io/dubbo-doc-static/User+Guide-zh.htm below to share my understanding of Dubbo, there may be misleading, but also to correct.

First, the Dubbo feelings


When I see this picture above, I have been recalling my previous development experience. This chart is a good summary of the development of the Java EE evolution of the entire architecture change process. One more Picture:

See this figure, reminds me of my college time contact service registration and discovery, then the service is the Web Service service, the service provider is through AXIS2 (of course, can also use CXF, about CXF can see @ Huang Yong Web Service that thing--using CXF to develop SOAP Service There is a detailed introduction to CXF), service registration and discovery is achieved through JUDDI. At that time, the Web Service service was registered to Juddi, and then the service was invoked, through the discovery service interface provided by JUDDI, the lookup service, the Discovery Service interface, the service quality of the service can be analyzed to give the best service (of course, this situation is the same service, there are multiple providers). For a moment I miss the time of college. So to see this picture let me have a very familiar feeling, so also instantly understand the meaning of this picture.

The general meaning of this picture is understood as:

    1. Responsibilities of the Registration center:

      (1) Request for acceptance of the service registration of the provider

      (2) be responsible for returning the service address of the customer's subscription to the consumer

      (3) Responsible for the service change, notify the consumer

      (4) Management of services within the registry
    2. Consumer: This will be the service that you need, the registration center initiates the subscription, and when the service changes, make adjustments.
    3. Service providers: Publish their services to a registry, and provide specific services to consumers.
    4. Monitoring center: Responsible for monitoring the number of service requests and processing time, convenient service governance.

It's the first time I've seen Dubbo's feelings. about how to use, and how to use, I do not do a lot of introduction here, I believe everyone to see the official documents can understand, the inside is very clear.

Second, Dubbo preliminary in-depth

Because I am a more impatient person, to Dubbo's GitHub website to download the source code to the local for a preliminary reading and analysis. View Dubbo source code, looks very large, but in-depth to see, inside the real core content is very small, that is Dubbo-common this is the core content of the whole Dubbo.
To say the core of Dubbo, its extension point of implementation is very great! Basically Dubbo everything is implemented on the basis of the extension point. For example, Dubbo supports Netty,mima or zookeeper, and these things are an extension point in Dubbo. So understanding the idea of Dubbo's extension point, then how to implement each of the other extension points of Dubbo, then it is relatively easy to point.

The extension point is the core of the Dubbo, and the core of the extension point is ExtensionLoader that the class is somewhat similar ClassLoader , but ExtensionLoader it is the extension point that loads the Dubbo. ExtensionLoaderSeveral important property structures are listed below.

  <!--Lang:java-->public class Extensionloader<t> {private static final Concurrentmap<class <?>, extensionloader<?>> extension_loaders = new Concurrenthashmap<class<?>, ExtensionLoader <?>> ();p rivate static final concurrentmap<class<?>, object> extension_instances = new Concurrenthashmap<class<?>, object> ();p rivate final class<?> type;private final ExtensionFactory Objectfactory;private final holder<map<string, class<?>>> cachedclasses = new Holder<Map< String,class<?>>> ();p rivate final holder<object> cachedadaptiveinstance = new Holder<Object> ();}

1, you can see that the EXTENSION_LOADERS property is a static final, then the description should be a constant, this is used to load all the extension points of Dubbo ExtensionLoader , in Dubbo, each type of extension point will have a corresponding ExtensionLoader , similar to each of the JVM Classthere will be one ClassLoader , each with ExtensionLoader multiple implementations of that extension point, similar to one that ClassLoader can load more than one specific class, but the difference ExtensionLoader is isolated and ClassLoader similar. Then understanding Dubbo ExtensionLoader can be used ClassLoader for analogy, which will speed up their understanding of it.

2, another constant attribute is EXTENSION_INSTANCES that he is a specific extension of the entity, for the cache, to prevent the extension point is heavier, resulting in wasting unnecessary resources, so when implementing the extension point, make sure that the extension point can be singleton, otherwise there may be problems.

3, another important attribute is the type, here the type is generally the interface, used to make the extension point type, because the Dubbo extension Point declaration is the way of SPI, so a certain type extension point, it is necessary to declare an extension point interface. For example ExtensionFactory , the extension point declaration is as follows:

<!-- lang:java -->@SPIpublic interface ExtensionFactory {/** * Get extension. *  * @param type object type. * @param name object name. * @return object instance. */<T> T getExtension(Class<T> type, String name);}

Dubbo loading a type of extension point is going to traverse three directories ( META-INF/services/ , META-INF/dubbo/ , META-INF/dubbo/internal/ ) below to find the Type.getname file, inside the content format is extendName=classFullName , so say type is to tell Dubbo the type of extension point, And how to find that type of extension point.

4, extension point of mutual dependency injection, Dubbo through ExtensionFactory to solve, for example SpringExtensionFactory SpiExtensionFactory , and, different extension points must exist between the dependencies, then its extension point from where to obtain, all handed ExtensionFactory to realize, through the above ExtensionFactory code can understand, To get a specific extension point implementation you need to know two parameters, the first is the extension point type, which is used to get which type of extension point, and the second is the name of the extension implementation that is used to find the corresponding implementation in an extension of a type. Note: It is also considered an extension in Dubbo, which means that there is ExtensionFactory no extension in Dubbo, and another point of note is that only the ExtensionFactory extension ExtensionLoader objectFactory is null, and the other extensions must have an ExtensionFactory implementation assigned to objectFactoryproperty. The following code allows you to know:

<!-- lang:java --> private ExtensionLoader(Class<?> type) {    this.type = type;    objectFactory = (type == ExtensionFactory.class ? null : ExtensionLoader.getExtensionLoader(ExtensionFactory.class).getAdaptiveExtension());}

5, the above code tells us a message, ExtensionLoader.getExtensionLoader(ExtensionFactory.class) after, not directly return to an extension point, but instead call getAdaptiveExtension to get an extended adapter, this is why? Because an extension point has multiple implementations of specific extensions, it is unreliable to directly ExtensionLoader return an extension, requiring an adapter to return a specific extension implementation based on the actual situation. So here is the existence of a cachedAdaptiveInstance property, Dubbo inside each extension ExtensionLoader has a cachedAdaptiveInstance , the type of this property must implement the ExtensionLoader.type interface, this is the design mode of the adapter mode. For example ExtensionFactory , an extension point has an AdaptiveExtensionFactory adapter. The adapter for an extension point can be either by itself @Adaptive or without an implementation, provided by Dubbo by dynamically generating adaptive to provide an adapter class. Note here: Adaptive is also an implementation of an extension point, the following example illustrates an ExtensionFactory adapter for an extension point:

  <!--Lang:java-@Adaptivepublic class Adaptiveextensionfactory implements Extensionfactory { Private final list<extensionfactory> factories;public adaptiveextensionfactory () {extensionloader<    extensionfactory> loader = Extensionloader.getextensionloader (Extensionfactory.class);    list<extensionfactory> list = new arraylist<extensionfactory> ();    For (String name:loader.getSupportedExtensions ()) {List.add (loader.getextension (name)); } factories = Collections.unmodifiablelist (list);}        Public <T> T getextension (class<t> type, String name) {for (extensionfactory factory:factories) {        T Extension = factory.getextension (type, name);        if (extension! = null) {return extension; }} return null;}}  

6, about the Dubbo extension point the last important attribute is cachedClasses that this is the storage of the current ExtensionLoader extension point implementation, so that you can instantiate a specific extension point entity, cachedClasses declared as a Holder<Map<String, Class<?>>> type, can actually be understood as a Map<String, Class<?>> type, The key to the map is the previous content in the Type.getname file = , value, which is the class object implemented by this extension point.

Iii. Summary

From the above analysis, we already know what Dubbo can do, and Dubbo's extension point implementation has a basic understanding. So summarize some points of Dubbo extension point

1, an extension point type must be an interface
2, an extension point must correspond to a ExtensionLoader
3, one ExtensionLoader must have a adapter
4, an extension point can have multiple implementations, and are loaded with one ExtensionLoader
5, one ExtensionLoader (except the ExtensionFactory extension) must have aExtensionFactory

To this, has completed a Dubbo simple sharing, also is a Dubbo understanding of the beginning of it. You are welcome to share the exchange.

Preliminary knowledge of Distributed service management framework-dubbo

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.