I developed the kafka consumer application based on Spring Cloud Stream 3.0.3.RELEASE. (SpringBoot 2.3.4.RELEASE)
When I stop this application, I want the consumer to gracefully shut down. Similar Questions
Does the spring cloud stream default this work? Then is there a related document?
For your information, I am using spring cloud stream kafka as below.
#Message handler
@Component
public class MessageHandler {
@Bean
public Consumer<MyEvent> handleMessage() {
return message -> {...}
}
...
}
#application.yml
spring:
cloud:
stream:
bindings:
handleMessage-in-0:
destination: myevent
group: test-group
consumer:
maxAttempts: 2
concurrency: 10
function:
definition: handleMessage
...
As mentioned in the answer you referenced, you can increase the shutdownTimeout container property (default 10 seconds) with a ListenerContainerCustomizer bean.
@Bean
public ListenerContainerCustomizer<AbstractMessageListenerContainer<?, ?>> customizer() {
return (container, dest, group) -> container.getContainerProperties()
.setShutdownTimeout(30_000L);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With