Spring Cloud Eureka Service Registry Source analysis

Source: Internet
Author: User

How does Eureka work?

That Eureka client how to send the registration information of the local service to the remote registered server Eureka server. through the following source analysis, we can see that the Eureka client's scheduled task calls the Eureka server's reset interface, and Eureka receives the call request to process the registration of the service and the synchronization of data in the Eureka server.

Service Registration

Source analysis, see Service registration can be considered as Eureka client self-completion, do not need the service itself to care.

Eureka Client's scheduled task calls Eureka server's provider Interface

When the com.netflix.discovery.DiscoveryClient is started, a timed task is initialized, and the local service configuration information, that is, the service information that needs to be registered to the remote, is automatically refreshed to the registration server.
First look at the Eureka code, in the Spring-cloud-netflix-eureka-server project can find this dependency Eureka-client-1.4.11.jar View code can be seen,
1240 rows in Com.netflix.discovery.DiscoveryClient.java can be seen initializes all scheduled tasks, in 1277 rows, You can see Instanceinforeplicator scheduled tasks

Initializing a instanceinforeplicator in discoveryclient is actually encapsulated with timed tasks.

/*** Initializes all scheduled tasks. */    Private voidinitscheduledtasks () {if(Clientconfig.shouldfetchregistry ()) {//Registry Cache Refresh Timer            intRegistryfetchintervalseconds =clientconfig.getregistryfetchintervalseconds (); intExpbackoffbound =Clientconfig.getcacherefreshexecutorexponentialbackoffbound (); Scheduler.schedule (NewTimedsupervisortask ("Cacherefresh", Scheduler, Cacherefreshexecutor, re                            Gistryfetchintervalseconds, Timeunit.seconds, Expbackoffbound, NewCacherefreshthread ()), Registryfetchintervalseconds, timeunit.seconds); }        if(Clientconfig.shouldregisterwitheureka ()) {intRenewalintervalinsecs =instanceinfo.getleaseinfo (). Getrenewalintervalinsecs (); intExpbackoffbound =Clientconfig.getheartbeatexecutorexponentialbackoffbound (); Logger.info ("Starting Heartbeat Executor:" + "Renew interval is:" +renewalintervalinsecs); //Heartbeat TimerScheduler.schedule (NewTimedsupervisortask ("Heartbeat", Scheduler, Heartbeatexecutor, renew                            Alintervalinsecs, Timeunit.seconds, Expbackoffbound, NewHeartbeatthread ()), Renewalintervalinsecs, timeunit.seconds); //Instanceinfo Replicator            /**The ************************ encapsulates a timed task **********************************/Instanceinforeplicator=NewInstanceinforeplicator ( This, Instanceinfo, Clientconfig.getinstanceinforeplicationintervalseconds (), 2);//burstsizeStatuschangelistener =NewApplicationinfomanager.statuschangelistener () {@Override PublicString getId () {return"Statuschangelistener"; } @Override Public voidNotify (Statuschangeevent statuschangeevent) {if(Instancestatus.down = = Statuschangeevent.getstatus () | |Instancestatus.down==Statuschangeevent.getpreviousstatus ()) {                        //log at warn level if off was involvedLogger.warn ("Saw Local status Change event {}", statuschangeevent); } Else{logger.info ("Saw Local status Change event {}", statuschangeevent);                } instanceinforeplicator.ondemandupdate ();            }            }; if(Clientconfig.shouldondemandupdatestatuschange ()) {Applicationinfomanager.registerstatuschangelistene            R (Statuschangelistener); }            //Click to view the Start methodInstanceinforeplicator.start (Clientconfig.getinitialinstanceinforeplicationintervalseconds ()); } Else{logger.info ("Not registering with Eureka server per configuration"); }    }

Eurekahttpclient: Provides a Eureka Client API approach

Spring Cloud Eureka Service Registry Source analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.