Kafka consumer sleep wakeup

174 Views Asked by At

Hello I have a batch using Spring boot with a kafka consumer annotated with @KafkaListener during treatment a have a static boolean that takes differents values during running I want to paused my consommer if true and wake it up when false I dont want to lose messages when the consumer is paused Info a have multiple partition for the topic How can I do that thank you

Paused my kafka listener if condition and not lose messages during this pause

1

There are 1 best solutions below

0
Artem Bilan On

The pause functionality on the container is just a request to move to that state when consume loop is ready. While you are in processing of your just pulled batch, that thread is blocked and cannot react to your pause request immediately. So, you really don't lose records you are processing now. The new batch is not going to be pulled because that consumer loop will see a pause request.

See more info in the docs: https://docs.spring.io/spring-kafka/reference/html/#pause-resume