使用 Spring Cloud Stream Kafka 3.0.3.RELEASE 时可以正常关闭吗? [英] Can I apply graceful shutdown when using Spring Cloud Stream Kafka 3.0.3.RELEASE?

查看:40
本文介绍了使用 Spring Cloud Stream Kafka 3.0.3.RELEASE 时可以正常关闭吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基于 Spring Cloud Stream 3.0.3.RELEASE 开发了 kafka 消费者应用程序.(SpringBoot 2.3.4.RELEASE)

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

  1. 停止轮询新消息
  2. 完成他们的工作并将偏移量提交给 Kafka
  3. 正常关闭应用程序

spring cloud 流默认这个能用吗?那有没有相关的文档?

Does the spring cloud stream default this work? Then is there a related document?

供您参考,我使用的是 spring cloud stream kafka,如下所示.

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
...

推荐答案

如您引用的答案中所述,您可以使用 ListenerContainerCustomizer 增加 shutdownTimeout 容器属性(默认为 10 秒) 豆.

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);
}

这篇关于使用 Spring Cloud Stream Kafka 3.0.3.RELEASE 时可以正常关闭吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆