0

I am trying to shutdown my RabbitMQ consumer (using spring cloud stream, @StreamListener) gracefully by increasing the shutdownTimeout to only timeout after 60 seconds. However, it keeps using the default value, which is 5 seconds. May I know if I have missed anything?

@Bean
ListenerContainerCustomizer<AbstractMessageListenerContainer> configure() {
    return ((container, destinationName, group) -> container.setShutdownTimeout(60000L));
}

...

@Configuration
@EnableBinding(LongScenarioSink.class)
public class LongScenarioListener {

  @StreamListener(LongScenarioSink.INPUT)
  public void processLongScenarioSink(String text) throws InterruptedException {
    log.info("started: " + text);
    Thread.sleep(50000);
    log.info("done");
  }
weikangchia
  • 537
  • 2
  • 6
  • 14
  • Can you confirm from debug that it really does not populate your `setShutdownTimeout(60000L)` down to the `shutdown()` call? See `SimpleMessageListenerContainer.shutdownAndWaitOrCallback()` for a break point where that `getShutdownTimeout()` is invoked. Otherwise it would be great to have some simple project from you to play with. Note: the `@StreamListener` is deprecated for a while already in favor for `Consumer` in your case. So, be sure that you use the latest Spring Cloud Stream version: https://spring.io/projects/spring-cloud-stream#learn – Artem Bilan Jun 24 '22 at 17:04
  • I have tried to debug by setting the break point at getShutdownTimeout and it is still 5s. Let me try your suggestion on create a simple project with the latest version – weikangchia Jun 25 '22 at 00:34
  • 1
    So, sounds like your `ListenerContainerCustomizer` is not called. Perhaps this is problem with visibility for binder-specific context: https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#multiple-systems. Specifically a `spring.main.sources` property. – Artem Bilan Jun 25 '22 at 00:39
  • Thank you @ArtemBilan, you are right, after setting my config to the spring.main.sources property, I am able to override the shutdown timeout now. – weikangchia Jun 25 '22 at 00:57

0 Answers0