0

I'm writing some simple Microservices to understand the way Netflix Eureka works.
I was wondering if there is a general possibility of programmatically shutting down a Service in Java, with immediate deregistration from the Eureka Service Registry as a result.
I found out the solution with the Spring Boot actuator endpoint (with a POST request to service-URL/actuator/shutdown).
How can the same result be reached in the case I wanted to shutdown a Service that is not Spring Boot based?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

in a very very abstract way, every process that run indefinitely, like a server that listen to requests is basically a while loop like

while flag:
  listen and process request 

shutdown is just an api effecting that flag and making the program to exist from the loop and resume a direct flow, one that will result in ending that program

so to shutdown a service that is not a spring boot, you need to create an api that can manipulate the code flow like above

also, spring boot is a very robust and minimal wrapper, so you can incorporate spring boot to almost any service and program in java

note that Eureka support manual overriding of services state, so you can tell Eureka to ignore and deregister one or more services regardless to their actual state

with most discovery services that work in passive mode (don't actively initiate contact with the services) like eureka each service send an health check every x time, the discovery server will know the service is offline only after x time has passed and an health check is due (there are some other parameters like thresholds and special operation modes that taken into consideration also)

I refer you to this post for more information about controlling the eviction rate of "spring-boot-eureka" (especially the last comment)

shahaf
  • 4,750
  • 2
  • 29
  • 32
  • Thank you! Very clear explanation of how it works! Any hints on how to reach that? What I don't understand, is why a simple SpringApplication.exit(...) or a termination from the IDE isn't enough to get an immediate deregistration. – Renata Samà Jun 16 '18 at 22:15