These are chat archives for spring-cloud/spring-cloud

26th
Feb 2019
Patrick Gotthard
@PatrickGotthard
Feb 26 07:37
hi. I'm searching for a possibility to unregister my service from eureka and wait for some time before shutting down my service. my current solution looks like this:
``````
@Configuration
@ConditionalOnProperty(name = "eureka.client.register-with-eureka", havingValue = "true")
@AllArgsConstructor
class EurekaShutdownConfiguration implements ApplicationListener<ContextClosedEvent> {

    private final EurekaClient client;

    @Override
    public void onApplicationEvent(final ContextClosedEvent event) {
        try {
            this.client.shutdown();
            Thread.sleep(10_000);
        } catch (final InterruptedException e) {
            // ignore
        }
    }

}
is this a viable solution or am i missing something?
the service itself will be called by a spring-cloud-gateway that fetches the registered service instances every 5 seconds from eureka
Marcos Barbero
@marcosbarbero
Feb 26 10:45

Hello @PatrickGotthard, how the actual shutdown works? Is it a manual process?
A while ago while I was using Eureka and had the same use-case where I wanted to deregister the instance from Eureka before shutting it down I've used the Eureka REST Operations.

I'd a script where before shutting down the instance I would first do the request to deregister it and afterwards shut the process down, in the between you can wait or do whatever is needed.

Patrick Gotthard
@PatrickGotthard
Feb 26 10:59
Hi @marcosbarbero. The service is not in production yet, we are currently building our new infrastructure. Without any customization the service will be shut down and some requests would get lost until the gateway notices that the instance is down
Marcos Barbero
@marcosbarbero
Feb 26 11:01
I got that part, I'm just not sure how you shutdown the instances.
If you use the rest operations provided by eureka itself you can deregister it and add a waiting time before the shutdown so the gateway will have time to fetch its new status
Patrick Gotthard
@PatrickGotthard
Feb 26 11:01
Unregistering the service via a REST call introduces another layer of complexity to the deployment. The service itself should unregister before shutting down, equally as it registers itself on startup
ok, we are currently shutting the service down via commany line
kill <pid>
automated via the bamboo deployment of course ;D
Marcos Barbero
@marcosbarbero
Feb 26 11:03
which application server are you using? tomcat?
Patrick Gotthard
@PatrickGotthard
Feb 26 11:03
correctly
waiting for pending requests to be processed is even not enough, if you want to give me a link to the corresponding github issue ;)
Marcos Barbero
@marcosbarbero
Feb 26 11:06
well, if you want to make the instance self-aware of its own de-registration then you're already doing it in the right way
Patrick Gotthard
@PatrickGotthard
Feb 26 11:09
is it guaranteed that tomcat will be shutdown after my ContextClosedEvent-listener? should I add an @Ordered with highest precedence to the config class?
Marcos Barbero
@marcosbarbero
Feb 26 12:34
you can try to also implement the TomcatConnectorCustomizer interface and add it to tomcat and then use the tomcat's tread to add the waiting time
Patrick Gotthard
@PatrickGotthard
Feb 26 12:59
First I've done this but I think that would be useless because the EventListener itself is responsible for the graceful shutdown, not the customizer
or am i missing something?
I've discovered another problem just yet. My spring-cloud-gateway is not fetching the registrered instances every 5 seconds. I thought that can be controlled by eureka.client.registry-fetch-interval-seconds: 5. Any hints how to configure the refresh interval?
Marcos Barbero
@marcosbarbero
Feb 26 13:17
So, you have some more properties to add, maybe this read can give you some insights, let me know if you have any more doubts
Patrick Gotthard
@PatrickGotthard
Feb 26 13:52

hmm it doesn't work. I've set

eureka.client.registry-fetch-interval-seconds: 5
ribbon.ServerListRefreshInterval: 5000

on the gateway server and

eureka.server.response-cache-update-interval-ms: 5000

for the eureka server. But it seems that the gateway is polling for updates only every 5 minutes:

2019-02-26 14:43:00.255  INFO 20713 --- [AsyncResolver-bootstrap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2019-02-26 14:48:00.768  INFO 20713 --- [AsyncResolver-bootstrap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
Patrick Gotthard
@PatrickGotthard
Feb 26 14:00
sorry, my fault. seems that this log message will be printed when looking for new eureka instances.
Marcos Barbero
@marcosbarbero
Feb 26 14:02
Here you can find a more complete list of properties that you can play with https://cloud.spring.io/spring-cloud-static/spring-cloud.html#_appendix_compendium_of_configuration_properties
I think eureka.client.eureka-service-url-poll-interval-seconds can help you
Patrick Gotthard
@PatrickGotthard
Feb 26 14:08
@marcosbarbero thank for your great support. I'll have a look at all properties tomorrow, now it's time to go home :)
Marcos Barbero
@marcosbarbero
Feb 26 14:09
Np! You can tag me if you need more help
Archimedes Trajano
@trajano
Feb 26 17:36
Hi I'm hitting the issue specified by https://stackoverflow.com/questions/36071841/spring-cloud-hystrix-fails-at-first-command-call I was wondering if there's any updates to that issue in the context of Gateway