Version:
SpringBoot 1.5.4.RELEASE
SpringCloud Dalston.RELEASE
What the article basically discusses is tiny service registers Eureka to register a center, use the case that Zuul gateway load visits, how to stop machine is OK make the user does not have perception.
Means one: Id of process of Kill -9 Java [do not suggest]
Kill -9 is belonged to kill a process by force, above all the mission that tiny service is executing was interrupted compulsively; Next, wu of the be convinced in was not being registered through Eureka gets offline, the road that Zuul gateway regards Eureka Client as to still save this service by information, can continue to call a service, http requests to return 500, tiring-room is Connection Refuse join refuses unusually
Acquiescent the longest need awaits this kind of circumstance:
90s (tiny service expires in the lease on Eureka Server) + 30s (refresh of list of Eureka Server service arrives read-only the time of cache ReadOnlyMap, eureka Client acquiesce reads this cache) + 30s (Zuul acquiesces as Eureka Client every 30 seconds are pulled take service list) + 30s (refresh of Ribbon acquiescent trends the time-interval of its ServerList) = 180s, namely 3 minutes
Summary:
This kind of means can bring about the task in be being carried out to cannot be carried out already, can bring about a service to was not excised from Eureka Server again, arrive to refresh of Eureka Client time service list, brought about still call the situation that already stopped a service to sign up for 500 mistakes through Zuul, do not recommend.
Means 2: Id of process of Kill -15 Java or use directly / Shutdown end points [do not suggest]
Kill and / the meaning of Shutdown
Above all, kill is equal to Kill -15, according to the descriptive information of Man Kill
The Command Kill Sends The Specified Signal To The Specified Process Or Process Group. If No Signal Is Specified, the TERM Signal Is Sent.
Namely Kill is equal without executive signal at TERM (stop, termination)
And Kill -l examines the impact between signal number and signal, kill -15 is SIGTERM, TERM signal
When sending TERM to end signal to JVM process, can call the Shutdown Hook that its register, also registered Shutdown Hook when SpringBoot tiny service is started
And call directly / essence of Shutdown end points and use Shutdown Hook is same, no matter be,use Kill or Kill -15 so, still use directly / Shutdown end points, can call the Shutdown Hook that registers to JVM
Attention:
Enable / Shutdown end points, need as follows to configure
Endpoints.shutdown.enabled = True
Endpoints.shutdown.sensitive = False
What did all problems direct Shutdown Hook can be carried out? ?
The Shutdown Hook that Spring registers
Use the place of Runtime.getRuntime().addShutdownHook(Thread ShutdownHook) through inquiring project group, discover Ribbon registered a few Shutdown Hook, but we do not pay close attention to this this, the applied context that what we pay close attention to is Spring is abstract kind AbstractApplicationContext registered the Shutdown Hook that is aimed at whole Spring container, the logic when executive Shutdown Hook is in AbstractApplicationContext#doClose()
/ / ## Org.springframework.context.support.AbstractApplicationContext#registerShutdownHook /** * Register A Shutdown Hook With The JVM Runtime, closing This Context * On JVM Shutdown Unless It Has Already Been Closed At That Time. * <p>Delegates To {@code DoClose()} For The Actual Closing Procedure. * @see Runtime#addShutdownHook * @see #close() * @see #doClose() */@Overridepublic Void RegisterShutdownHook() {If (this.shutdownHook==Null) {// No Shutdown Hook Registered Yet. / / register ShutdownHook, what line Cheng is calling really is DoClose() This.shutdownHook = New Thread() {@Override Public Void Run() {Synchronized (startupShutdownMonitor) {DoClose(); } } }; Runtime.getRuntime().addShutdownHook(this.shutdownHook); }}//## Org.springframework.context.support.AbstractApplicationCon: Publishes A ContextClosedEvent And * Destroys The Singletons In The Bean Factory Of This Application Context. * <p>Called By Both {@code Close()} And A JVM Shutdown Hook, if Any. * @see Org.springframework.context.event.ContextClosedEvent * @see #destroyBeans() * @see #close() * @see #registerShutdownHook() */protected Void DoClose() {If (this.active.get() &&This.closed.compareAndSet(false, true)) {If (logger.isInfoEnabled()) {Logger.info("Closing " + This); } // cancels registered MBean LiveBeansView.unregisterApplicationContext(this); Try {// Publish Shutdown Event. / / send ContextClosedEvent episode, can have correspondence the logistic PublishEvent(new ContextClosedEvent(this)); } Catch (Throwable Ex) {Logger.warn("Exception Thrown From ApplicationListener Handling ContextClosedEvent with the Listener corresponding processing of this incident