org.springframework.batch.item.kafka

## 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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.springframework.kafka.core.KafkaTemplate<K,T>` | `kafkaTemplate`

    - ### Fields inherited from class org.springframework.batch.item.KeyValueItemWriter

      `delete, itemKeyMapper`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `KafkaItemWriter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `flush()` Flush items to the key/value store.
    `protected void` | `init()` afterPropertiesSet() hook
    `void` | `setKafkaTemplate(org.springframework.kafka.core.KafkaTemplate<K,T> kafkaTemplate)` Set the `KafkaTemplate` to use.
    `void` | `setTimeout(long timeout)` The time limit to wait when flushing items to Kafka.
    `protected void` | `writeKeyValue(K key, T value)` Subclasses implement this method to write each item to key value store

    - ### Methods inherited from class org.springframework.batch.item.KeyValueItemWriter

      `afterPropertiesSet, setDelete, setItemKeyMapper, write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### kafkaTemplate

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

  - ### Constructor Detail

    - #### KafkaItemWriter

          public KafkaItemWriter()

  - ### Method Detail

    - #### 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 java.lang.Exception

      Description copied from class: `KeyValueItemWriter`
      Flush items to the key/value store.
      Overrides:
        `flush` in class `KeyValueItemWriter<K,T>`
      Throws:
        `java.lang.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