The service registration in Eureka is divided into service registration center, and service registration.
One, service registrant
The service registrant registers itself on the Eureka server when it is started by sending a rest request. Eureka server stores the original information of the service registration on a double-layered map, the first key is the service name, and the second tier key is the specific service instance name.
After the registration is complete, the service provider will maintain a heartbeat to persist, calling the renewal service interval through Eureka. Instance.less-renewal-interval-in-seconds to set the default is 30 seconds.
To turn on the provider of the service, we configure it via @enablediscoveryclient.
Its main role is to open an example of a discoveryclient
/**
* Annotation to enable a discoveryclient implementation.
* @author Spencer Gibb
*/
In the Eureka implementation of the service governance corresponds to the implementation of eurekadiscoveryclient, specifically through the implementation of Eurekaclient is discoveryclient to complete.
Second, the registration center.
The registry accepts and processes requests from service registrants, and the logic for processing registration requests is in Applicationresource's Addinstance method.
After the checksum is completed, registration is done through the Regist method in Instanceregistry.
public void Register (instanceinfo info, int leaseduration, Boolean isreplication) {
Handleregistration (info, leaseduration, isreplication);
Super.register (info, leaseduration, isreplication);
}
private void Handleregistration (instanceinfo info, int leaseduration,
Boolean isreplication) {
Log ("register" + info.getappname () + ", VIP" + info.getvipaddress ()
+ ", leaseduration" + Leaseduration + ", isreplication"
+ isreplication);
Publishevent (New Eurekainstanceregisteredevent (this, info, leaseduration,
isreplication));
}
In the Handleregistration method, broadcast the event registered by the service.
The parent class's method is then called to complete the registration.
Service registration for Eureka in Spring Cloud