Class DefaultConsumerRunnable<K,V>

java.lang.Object
com.bakdata.kafka.consumer.DefaultConsumerRunnable<K,V>
Type Parameters:
K - type of keys
V - type of values
All Implemented Interfaces:
ConsumerRunnable, AutoCloseable

public class DefaultConsumerRunnable<K,V> extends Object implements ConsumerRunnable
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 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 new DefaultConsumerRunnable instance.
      Parameters:
      consumer -
      executionOptions -
      recordProcessor - The processor that implements the logic for handling each batch of ConsumerRecords polled from Kafka.
  • Method Details

    • run

      public void run(org.apache.kafka.clients.consumer.ConsumerConfig consumerConfig)
      Run the application.
      Specified by:
      run in interface ConsumerRunnable
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface ConsumerRunnable
    • getConsumer

      public org.apache.kafka.clients.consumer.Consumer<K,V> getConsumer()