How to Quickly Remove Unresponsive Services from Eureka Registry
This article explains why stopped services may still be called through Eureka, shows how to adjust eviction and lease settings in the registry and client, and presents three active methods—including direct shutdown, DELETE requests, and client‑initiated deregistration—with code examples for Spring Boot applications.
When multiple instances of a service are deployed, the gateway randomly selects one, but if an instance crashes it may remain registered in Eureka and still be chosen, causing timeout errors. During development or demos you often need to remove the failed instance immediately.
1. Reduce the eviction interval in the Eureka server. The default is 60 seconds; set eureka.server.eviction-interval-timer-in-ms to a smaller value (e.g., 4000 ms). Example configuration:
eureka:
instance:
hostname: localhost
lease-expiration-duration-in-seconds: 90
lease-renewal-interval-in-seconds: 30
prefer-ip-address: true
server:
enable-self-preservation: true
eviction-interval-timer-in-ms: 4000
client:
enabled: true
fetchRegistry: false
instance-info-replication-interval-seconds: 30
registry-fetch-interval-seconds: 30
registerWithEureka: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/2. Shorten the lease expiration and renewal intervals in each microservice. Example:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true # register by IP
ip-address: 192.168.217.211
non-secure-port: 8767
lease-renewal-interval-in-seconds: 10
lease-expiration-duration-in-seconds: 30Note: Changing these frequencies disables Eureka’s self‑preservation feature.
Other ways to actively deregister a service
1. Stop the service directly. By default Eureka removes an instance after 90 seconds without a heartbeat, but the instance may still appear in the registry for a short period.
2. Send a DELETE request to the Eureka server. The URL format is /eureka/apps/{application.name}/. After sending the request, the instance is removed immediately. Be aware that the client will re‑register if it continues sending heartbeats.
3. Let the client notify the registry. In a Spring Boot application you can call the Eureka client’s shutdown method:
@RestController
public class HelloController {
@Autowired
private DiscoveryClient client;
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String index() {
java.util.List<ServiceInstance> instances = client.getInstances("hello-service");
return "Hello World";
}
@RequestMapping(value = "/offline", method = RequestMethod.GET)
public void offLine() {
DiscoveryManager.getInstance().shutdownComponent();
}
}Typically you stop the service first, then invoke the DELETE request or the client shutdown to ensure the instance disappears from the registry promptly.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
