Package com.bakdata.kafka.consumer
Class DefaultConsumerRunnable<K,V>
java.lang.Object
com.bakdata.kafka.consumer.DefaultConsumerRunnable<K,V>
- Type Parameters:
K- type of keysV- type of values
- All Implemented Interfaces:
ConsumerRunnable,AutoCloseable
Default implementation of
ConsumerRunnable that manages the Kafka consumer poll loop and record processing
lifecycle. This class handles the consumer poll loop, automatic offset commits, and graceful shutdown. It delegates
record processing to the provided Consumer.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultConsumerRunnable(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, ConsumerExecutionOptions executionOptions, Consumer<org.apache.kafka.clients.consumer.ConsumerRecords<K, V>> recordProcessor) Creates a newDefaultConsumerRunnableinstance. -
Method Summary
-
Constructor Details
-
DefaultConsumerRunnable
protected DefaultConsumerRunnable(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, ConsumerExecutionOptions executionOptions, Consumer<org.apache.kafka.clients.consumer.ConsumerRecords<K, V>> recordProcessor) Creates a newDefaultConsumerRunnableinstance.- Parameters:
consumer-executionOptions-recordProcessor- The processor that implements the logic for handling each batch ofConsumerRecordspolled from Kafka.
-
-
Method Details
-
run
public void run(org.apache.kafka.clients.consumer.ConsumerConfig consumerConfig) Run the application.- Specified by:
runin interfaceConsumerRunnable- Parameters:
consumerConfig- configuration for the consumer
-
close
public void close()Gracefully shut down the consumer. This method triggers a wakeup of the consumer poll, waits for the poll loop to complete, and ensures all resources are properly cleaned up. This method is thread-safe and can be called from any thread. If the consumer is not running or is already stopping, this method returns immediately.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConsumerRunnable
-
getConsumer
-