如何优雅地关闭 spring-kafka 消费者应用程序

ora*_*doa 3 java apache-kafka spring-boot kafka-consumer-api spring-kafka

我已经实现了spring-kafka消费者应用程序。

我想要消费者应用程序正常关闭。

当前的消费者应用程序使用 Linux 命令终止 kill -9 pid

我现在正在使用@KafkaListener注释。

如果我退出 Spring Boot 应用程序,我想可靠地关闭消费者,我该怎么办?


我一直在使用@Predestory以可靠地退出 spring boot 应用程序,但我不太确定这是否与它有关。

Gar*_*ell 5

kill -9 就像死星

     Some of the more commonly used signals:

     1       HUP (hang up)
     2       INT (interrupt)
     3       QUIT (quit)
     6       ABRT (abort)
     9       KILL (non-catchable, non-ignorable kill)
     14      ALRM (alarm clock)
     15      TERM (software termination signal)
Run Code Online (Sandbox Code Playgroud)

默认的kill信号SIGTERM (15)

kill <pid>

Boot 将优雅地关闭一切;它注册了一个关闭钩子,它不能拦截kill -9.