Class KafkaItemWriter<K,T>

java.lang.Object
org.springframework.batch.item.KeyValueItemWriter<K,T>
org.springframework.batch.item.kafka.KafkaItemWriter<K,T>
All Implemented Interfaces:
ItemWriter<T>, org.springframework.beans.factory.InitializingBean

public class KafkaItemWriter<K,T> extends KeyValueItemWriter<K,T>

An ItemWriter implementation for Apache Kafka using a KafkaTemplate with default topic configured.

Since:
4.2
Author:
Mathieu Ouellet, Mahmoud Ben Hassine
  • Field Details

    • kafkaTemplate

      protected org.springframework.kafka.core.KafkaTemplate<K,T> kafkaTemplate
  • Constructor Details

    • KafkaItemWriter

      public KafkaItemWriter()
  • Method Details

    • writeKeyValue

      protected void writeKeyValue(K key, T value)
      Description copied from class: KeyValueItemWriter
      Subclasses implement this method to write each item to key value store
      Specified by:
      writeKeyValue in class KeyValueItemWriter<K,T>
      Parameters:
      key - the key
      value - the item
    • flush

      protected void flush() throws Exception
      Description copied from class: KeyValueItemWriter
      Flush items to the key/value store.
      Overrides:
      flush in class KeyValueItemWriter<K,T>
      Throws:
      Exception - if unable to flush items
    • init

      protected void init()
      Description copied from class: KeyValueItemWriter
      afterPropertiesSet() hook
      Specified by:
      init in class KeyValueItemWriter<K,T>
    • setKafkaTemplate

      public void setKafkaTemplate(org.springframework.kafka.core.KafkaTemplate<K,T> kafkaTemplate)
      Set the KafkaTemplate to use.
      Parameters:
      kafkaTemplate - to use
    • setTimeout

      public void setTimeout(long timeout)
      The time limit to wait when flushing items to Kafka.
      Parameters:
      timeout - milliseconds to wait, defaults to -1 (no timeout).
      Since:
      4.3.2