Search⌘ K

Stopping a Consumer

Explore how to properly stop a Kafka consumer running in an infinite poll loop by using the wakeup() method to safely interrupt polling and close() to commit offsets. Understand how to implement a shutdown hook for consumers in the main thread to ensure graceful shutdown and prompt broker rebalancing.

We'll cover the following...

In the previous lessons, we showed code for the Kafka consumer that ran an infinite poll loop. This brings up the question of how we can gracefully stop a consumer. The KafkaConsumer object exposes a method wakeup() that can be invoked from a different thread to stop the consumer. Note that ...