Class KafkaItemReaderBuilder<K,V>

java.lang.Object
org.springframework.batch.item.kafka.builder.KafkaItemReaderBuilder<K,V>

public class KafkaItemReaderBuilder<K,V> extends Object
A builder implementation for the KafkaItemReader.
Since:
4.2
Author:
Mathieu Ouellet, Mahmoud Ben Hassine
See Also:
  • Constructor Details

    • KafkaItemReaderBuilder

      public KafkaItemReaderBuilder()
  • Method Details

    • saveState

      public KafkaItemReaderBuilder<K,V> saveState(boolean saveState)
      Configure if the state of the ItemStreamSupport should be persisted within the ExecutionContext for restart purposes.
      Parameters:
      saveState - defaults to true
      Returns:
      The current instance of the builder.
    • name

      public KafkaItemReaderBuilder<K,V> name(String name)
      The name used to calculate the key within the ExecutionContext. Required if saveState(boolean) is set to true.
      Parameters:
      name - name of the reader instance
      Returns:
      The current instance of the builder.
      See Also:
    • consumerProperties

      public KafkaItemReaderBuilder<K,V> consumerProperties(Properties consumerProperties)
      Configure the underlying consumer properties.

      consumerProperties must contain the following keys: 'bootstrap.servers', 'group.id', 'key.deserializer' and 'value.deserializer'

      .
      Parameters:
      consumerProperties - properties of the consumer
      Returns:
      The current instance of the builder.
    • partitions

      public KafkaItemReaderBuilder<K,V> partitions(Integer... partitions)
      A list of partitions to manually assign to the consumer.
      Parameters:
      partitions - list of partitions to assign to the consumer
      Returns:
      The current instance of the builder.
    • partitions

      public KafkaItemReaderBuilder<K,V> partitions(List<Integer> partitions)
      A list of partitions to manually assign to the consumer.
      Parameters:
      partitions - list of partitions to assign to the consumer
      Returns:
      The current instance of the builder.
    • partitionOffsets

      public KafkaItemReaderBuilder<K,V> partitionOffsets(Map<org.apache.kafka.common.TopicPartition,Long> partitionOffsets)
      Setter for partition offsets. This mapping tells the reader the offset to start reading from in each partition. This is optional, defaults to starting from offset 0 in each partition. Passing an empty map makes the reader start from the offset stored in Kafka for the consumer group ID.

      In case of a restart, offsets stored in the execution context will take precedence.

      Parameters:
      partitionOffsets - mapping of starting offset in each partition
      Returns:
      The current instance of the builder.
    • topic

      public KafkaItemReaderBuilder<K,V> topic(String topic)
      A topic name to manually assign to the consumer.
      Parameters:
      topic - name to assign to the consumer
      Returns:
      The current instance of the builder.
    • pollTimeout

      public KafkaItemReaderBuilder<K,V> pollTimeout(Duration pollTimeout)
      Set the pollTimeout for the poll() operations. Default to 30 seconds.
      Parameters:
      pollTimeout - timeout for the poll operation
      Returns:
      The current instance of the builder.
      See Also:
    • build

      public KafkaItemReader<K,V> build()