Java online learning-realization of NacosServiceRegistry

Luban College java source learning

In the NacosServiceRegistry.registry method, the nameingService.registerInstance in the Nacos Client SDK is called to complete the service registration.

Java online learning-realization of NacosServiceRegistry

Let's look at the implementation of the namingService.registerInstance() method. The main logic is as follows:

Through beatReactor.addBeatInfo to create heartbeat information to achieve health detection, Nacos Server must ensure that the registered service instance is healthy, and heartbeat detection is a means of service health detection.

serverProxy.registerService implements service registration.

Java online learning-realization of NacosServiceRegistry

Regarding the logic of service registration, our follow-up analysis will focus on the heartbeat mechanism implemented by beatReactor.addBeatInfo. The code is as follows:

Java online learning-realization of NacosServiceRegistry

From the above code, the so-called heartbeat mechanism is that the client sends a data packet to the server periodically through the schedule, and then starts a thread to continuously check the response of the server. If the response from the server is not received within the set time, the server is considered to appear. Fault. The Nacos server will continuously update the status of the service according to the client's heartbeat packet.

Guess you like

Origin blog.51cto.com/14873808/2540531