首页 > 解决方案 > 如何优雅地关闭 spring-kafka 消费者应用程序

问题描述

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

我希望消费者应用程序正常关闭。

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

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

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


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

标签: javaspring-bootapache-kafkakafka-consumer-apispring-kafka

解决方案


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)

默认终止信号 SIGTERM (15)

kill <pid>

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


推荐阅读