preface

Everybody is good, today began to share – Dubbo service registration and discovery of Dubbo project: in the last chapter we simply introduced the four roles in Dubbo, service registration and service discovery involved which we expose a local service to invoke a remote client and local client references a remote service process. So let’s get started!

1. What is service registration

From the discussion in the previous section, we know that both service providers and service consumers register service-related meta-information with the registry (see the previous section for specific meta-information). When we need to expose a service to other applications how does the application know where our service is? What interfaces are exposed? What is the communication port? How does the client get this information? All of these require our service provider to register with our registry, and the consumer side to obtain these registration meta information and make remote calls. The process by which the service provider registers meta information with the registry is called service registration. The whole service registration process roughly includes: parameter detection, URL assembly, local service export, remote service export, registry service registration.

2. What are service references

Service references in Dubbo occur in two cases: Spring container callback lifecycle method afterPropertiesSet and when the service is injected into other class references. Obviously the first one is as long as the Spring container will go start all afterPropertiesSet callback methods callback belongs to a way of the hungry type (come up to open a dry), and the other one is belong to LanHanShi when we use injection way (using sex only when). Both methods have their advantages and disadvantages: Hungry can check the validity of the application container when it is started, while lazy loading improves the startup speed of the application but also introduces some problems that can only be detected when it is used.

I’m talking about Dubbo 2.6.x and earlier, only the second version exists in Dubbo 2.7.x. A reference to a service is simply a proxy object for a call to the remote service.

3. Service registration and discovery process in Dubbo

  • Service Registration Process

  1. The ContextRefreshedEvent event will be published when our Spring container is started, Then the Dubbo through receiving ContextRefreshedEvent DubboBootstrapApplicationListener listening class events.

    ** This is where Dubbo’s integration with Spring comes in.

  2. When a listener receives a ContextRefreshedEvent event, Dubbo does the following: exposes the service, exports metadata, registers a local service instance, and initializes a remote invocation proxy object. Export metadata (metadata and configuration information are separated in Dubbo2.7.x, only metadata is exported), register the local instance (export the service in the JVM), initialize the remote proxy object (essentially create an Invoker proxy object that calls the remote).

  3. Here we focus on exposing services, so exposing services does the following things. The first part is pre-work: mainly used to check parameters and assemble urls. The second part is exporting services: it includes exporting services to local (JVM) and exporting services to remote. The third part is registering services with the registry: for service discovery.

  • Service discovery process

  1. First of all, our ReferenceBean implements the FactoryBean interface. As any Spring friend knows, getObject is invoked when we do dependency injection or dependency lookup bean through the Spring container. ReferenceBean rewrites this method, so ReferenceBean#getObject triggers a callback when the bean is fetched from the Spring container.

    ** This is the entry point for the entire service reference.

  2. The getObject overloaded method is called, first checking configuration properties, parameter verification, and so on.

  3. Check Local stubs and mock checks. (More on this later)

  4. Create a remote proxy object.

Above process analysis we can according to I to Dubbo 2.7 x source annotation study together, the analysis of the code entry class DubboBootstrapApplicationListener# onApplicationContextEvent.

Code address: github.com/liyong10288…

** Code is based on version 2.7.x.

4. Summary

In this section, we mainly studied the concepts of service registration and service reference in Dubbo, and took an in-depth look at the main flow of service registration and service reference and the two entry points for integrating with Spring: DubboBootstrapApplicationListener# onApplicationContextEvent, ReferenceBean# getObject, Also note some differences between Dubbo 2.6.x and Dubbo 2.7.x.

The highlights of this lesson are as follows:

  1. Understand service registration in Dubbo

  2. Understand service references in Dubbo

  3. Understand the service registration process in Dubbo

  4. Learn about service registry references in Dubbo

  5. See where Dubbo’s integration with Spring comes in

The author

Personally engaged in the financial industry, I have worked in chongqing’s first-class technical team of Yiji Pay, Sijian Technology and an online car hailing platform, and now I am working in a bank responsible for the construction of unified payment system. I have a strong interest in the financial industry. It also practices big data, data storage, automated integration and deployment, distributed microservices, responsive programming, and artificial intelligence. At the same time, he is also keen on technology sharing, creating public accounts and blog sites to share knowledge system. Concern public number: young IT male get latest technical article push!

Blog: Youngitman.tech

CSDN: blog.csdn.net/liyong10288…

Wechat Official Account:

Technical Exchange Group: