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.
This writer is not thread-safe.
- Since:
- 4.2
- Author:
- Mathieu Ouellet, Mahmoud Ben Hassine
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<CompletableFuture<org.springframework.kafka.support.SendResult<K,T>>> Fields inherited from class org.springframework.batch.item.KeyValueItemWriter
delete, itemKeyMapper -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidflush()Flush items to the key/value store.protected voidinit()afterPropertiesSet() hookvoidsetKafkaTemplate(org.springframework.kafka.core.KafkaTemplate<K, T> kafkaTemplate) Set theKafkaTemplateto use.voidsetTimeout(long timeout) The time limit to wait when flushing items to Kafka.protected voidwriteKeyValue(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
-
completableFutures
protected final List<CompletableFuture<org.springframework.kafka.support.SendResult<K,T>>> completableFutures
-
-
Constructor Details
-
KafkaItemWriter
public KafkaItemWriter()
-
-
Method Details
-
writeKeyValue
Description copied from class:KeyValueItemWriterSubclasses implement this method to write each item to key value store- Specified by:
writeKeyValuein classKeyValueItemWriter<K,T> - Parameters:
key- the keyvalue- the item
-
flush
Description copied from class:KeyValueItemWriterFlush items to the key/value store.- Overrides:
flushin classKeyValueItemWriter<K,T> - Throws:
Exception- if unable to flush items
-
init
protected void init()Description copied from class:KeyValueItemWriterafterPropertiesSet() hook- Specified by:
initin classKeyValueItemWriter<K,T>
-
setKafkaTemplate
Set theKafkaTemplateto 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
-