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
An ItemWriter
implementation for Apache Kafka using a KafkaTemplate
with default topic configured.
- Since:
- 4.2
- Author:
- Mathieu Ouellet, Mahmoud Ben Hassine
-
Field Summary
Modifier and TypeFieldDescriptionFields inherited from class org.springframework.batch.item.KeyValueItemWriter
delete, itemKeyMapper
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
flush()
Flush items to the key/value store.protected void
init()
afterPropertiesSet() hookvoid
setKafkaTemplate
(org.springframework.kafka.core.KafkaTemplate<K, T> kafkaTemplate) Set theKafkaTemplate
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 storeMethods inherited from class org.springframework.batch.item.KeyValueItemWriter
afterPropertiesSet, setDelete, setItemKeyMapper, write
-
Field Details
-
kafkaTemplate
-
-
Constructor Details
-
KafkaItemWriter
public KafkaItemWriter()
-
-
Method Details
-
writeKeyValue
Description copied from class:KeyValueItemWriter
Subclasses implement this method to write each item to key value store- Specified by:
writeKeyValue
in classKeyValueItemWriter<K,
T> - Parameters:
key
- the keyvalue
- the item
-
flush
Description copied from class:KeyValueItemWriter
Flush items to the key/value store.- Overrides:
flush
in classKeyValueItemWriter<K,
T> - Throws:
Exception
- if unable to flush items
-
init
protected void init()Description copied from class:KeyValueItemWriter
afterPropertiesSet() hook- Specified by:
init
in classKeyValueItemWriter<K,
T>
-
setKafkaTemplate
Set theKafkaTemplate
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
-