1

what's the situation? A Java programmer who has worked for 5 years, can't answer this question?

"How does Dubbo dynamically sense service offline"?

Well, for this question, look at the answers of ordinary people and experts!

Ordinary people:

Ok. . . . . . . . . . . .

Expert:

Ok, interviewer, I will answer this question from several aspects.

First of all, Dubbo uses Zookeeper by default to realize service registration and service discovery. In short, it is the communication address between multiple Dubbo services, which is maintained by Zookeeper.

On Zookeeper, a tree structure is used to maintain the protocol address of the Dubbo service provider

image-20220418135415703

The Dubbo service consumer will look up the address list of the target service from the Zookeeper Server, so as to complete the service registration and consumption functions.

Zookeeper will use the heartbeat detection mechanism to judge the running status of the Dubbo service provider to decide whether the service should be removed from the address list.

image-20220418135932445

When the Dubbo service provider fails, Zookeeper removes the address of this service,

Then the Dubbo service consumer needs to perceive the change of the address, so as to avoid subsequent requests being sent to the faulty node, resulting in request failure.

That is to say, Dubbo needs to provide the dynamic perception ability of service offline.

This capability is achieved through the Watch mechanism provided in Zookeeper

image-20220418141213603

To put it simply, the Dubbo service consumer will use the Watch in Zookeeper to register and monitor the /providers node registration and monitoring of the Zookeeper Server.

Once the child node under this node changes, Zookeeper Server will send an event to notify Dubbo Client.

After the Dubbo client receives the event, it will delete the service address in the local cache, so that the request will not be sent to the failed node in the future to complete the service offline awareness.

The above is my understanding of the problem!

Summarize:

Dubbo is currently a very mainstream open source RPC framework, which is used in many enterprises.

It is necessary to understand the underlying working principle of this RPC, which can help developers improve the efficiency of solving development problems.

Still want to say one more thing, in the position of Java, if you want to go further, you must work hard.

This issue of ordinary people VS master interview series ends here.

If you have any technical interview questions that you don't understand, please feel free to private message me at any time.

file

Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source for Mic带你学架构 !
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!

跟着Mic学架构
810 声望1.1k 粉丝

《Spring Cloud Alibaba 微服务原理与实战》、《Java并发编程深度理解及实战》作者。 咕泡教育联合创始人,12年开发架构经验,对分布式微服务、高并发领域有非常丰富的实战经验。