Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 789
oraedoa Avatar asked Dec 31 '22 02:12

oraedoa


2 Answers

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.

like image 163
Gary Russell Avatar answered Jan 02 '23 14:01

Gary Russell


If you want to stop a single consumer, just call stop() on the listener container.


Note that when you call stop() the container will process all records that have been fetched from poll() until that point, before the container shuts down.

like image 22
Giorgos Myrianthous Avatar answered Jan 02 '23 16:01

Giorgos Myrianthous