How to gracefully shutdown spring-kafka consumer application

i have implemented spring-kafka consumer application.

i wants consumer application graceful shutdown.

the current consumer application is terminated with the Linux command kill -9 pid

i am using @KafkaListener annotation now.

if i quit the Spring boot app, i want to reliably close the consumer, what should i do ?

i’ve been using @Predestory to reliably exit the spring boot app, but i’m not quite sure if this has anything to do with it.


kill -9 is like the death star

     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)

The default kill signal SIGTERM (15)

kill <pid>

Boot will shut down everything gracefully; it registers a shutdown hook, which can’t intercept a kill -9.

Source: stackoverflow