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.
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.
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:
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.