1Overall design
Dubbo overall design and call with link reference to the official website http://dubbo.apache.org/zh-cn/docs/dev/design.html
2Dubbo’s registry
1、Please refer to the official website of the registration center http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html
2、ZK Registration Center
2.1 directory structure
+- dubbo
+- consumers
+- consumer://192.168.1.102/com.demo.service.HelloService?application=dubbo-demo-annotation-consumer&category=consumers&check=false&dubbo=2.0.2&init=false&interface=com.lagou.service.HelloService***
+- providers


(2) Main components
1) Protocol: generally, our provider or consumer are man-made specific protocols
2) , host: the specific address of the current provider or other protocols. For example, the host specified by the override protocol is 0.0.0.0, which means that all machines are effective

2.3 service local cache
As can be seen from the above two figures, service providers will actively register their services in the registry when they start, while service consumers will also go to the registry to obtain their referenced service list locally and save it to a file when they start, and need to subscribe to the corresponding service provider node. When the service provider has information change, the consumer will receive the node change notification, and then get the latest service list and the new local cache file.

You can see that there are two methods: 1. Register; 2. Cancel.
org.apache.dubbo . registry.RegistryService This class is mainly used to register, log off, listen, cancel listening and query the specified path. It is also the most basic class in the registry
Abstract registry is the encapsulation of the registry, which mainly encapsulates the local registration address. Its main function is to use the local registry when the remote registry is not available
Next, let’s look at his implementation class org.apache.dubbo . registry.support.AbstractRegistry#AbstractRegistry The concrete realization of the construction method of
In fact, the main thing here is to cache the URL to the local file
2.4、Service registrationprocess analysis
1. Service registration sequence diagram
2. Service registration process
Note: the process of service registration can be roughly divided into two processes: 1. A specific service is converted into an invocker; 2. An invocker is converted into an exporter

As you can see from the picture above, org.apache.dubbo . config.spring.ServiceBean It inherits serviceconfig and implements a bunch of spring components. Students familiar with spring should know that in the life cycle of spring container, these components will be initialized.
Next, let’s focus on the proxyfactory, protocol and ref properties in serviceconfig
Next, let’s look at the protocol interface
We can see that the top-level interface of the protocol provides an interface for exposing and referencing services. It has many implementation classes, but we register to use org.apache.dubbo . registry.integration.RegistryProtocol
Next, let’s take a look at how to convert a serviceconfig to an invoker. Because the method is long, we won’t take a detailed screenshot
org.apache.dubbo.config.ServiceConfig#export
org.apache.dubbo.config.ServiceConfig#doExport
org.apache.dubbo.config.ServiceConfig#doExportUrls
org.apache.dubbo.config.ServiceConfig#doExportUrlsFor1Protocol
Now let’s look back org.apache.dubbo . registry.integration.RegistryProtocol#export This method
This method mainly does five things
1. Get the URL of the registry: zookeeper://127.0.0.1 :2181/ org.apache.dubbo . registry.RegistryService?application= * * *
2. Get the URL of the service provider: dubbo://192.168.1.102 :20880/ com.demo.service .HelloService?anyhost=**
3. Get the registry
4. Register the service provider in the registry
5. Returns the exposed object
Now let’s look at it again org.apache.dubbo . registry.integration.RegistryProtocol . destroyableexporter class
He mainly provides a method to obtain the invocker
Let’s look at the registration method
You can see that the factory mode is used to obtain the specific factory. Next, let’s take a look at the factory interface of the registry
org.apache.dubbo . registry.RegistryFactory It is a registry factory. In this way, you can also ensure that multiple registries can be used in an application. You can see that different protocols are selected through different protocol parameters
Now let’s take a look org.apache.dubbo . registry.support.FailbackRegistry#register
There are three main things to do here
1. Put the current URL into the registered list
2. Process URL for registration failure
3. Actually handle the registration of the current URL
If we look at the registration method that actually processes the current URL, we will find that this is a template method, which needs subclasses to provide specific implementation
Since Dubbo uses ZK as the registry by default, let’s take a look at the implementation of ZK
See here, the process of service registration is OK.