Class KafkaCheckpointCommit
- java.lang.Object
-
- io.smallrye.reactive.messaging.kafka.commit.ContextHolder
-
- io.smallrye.reactive.messaging.kafka.commit.KafkaCheckpointCommit
-
- All Implemented Interfaces:
KafkaCommitHandler
- Direct Known Subclasses:
KafkaFileCheckpointCommit
@Experimental("Experimental API") public abstract class KafkaCheckpointCommit extends ContextHolder implements KafkaCommitHandlerAbstract commit handler for checkpointing processing state on a state store Instead of committing topic-partition offsets back to Kafka, checkpointing commit handlers persist and restore offsets on an external store. It associates aProcessingStatewith a topic-partition offset, and lets the processing resume from the checkpointed state. This abstract implementation holds a local map ofProcessingStateper topic-partition, and ensures it is accessed on the captured Vert.x context. Concrete implementations providefetchProcessingState(TopicPartition)andpersistProcessingState(TopicPartition, ProcessingState)depending on the state store.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.smallrye.reactive.messaging.kafka.commit.KafkaCommitHandler
KafkaCommitHandler.Factory, KafkaCommitHandler.Strategy
-
-
Field Summary
Fields Modifier and Type Field Description protected KafkaConnectorIncomingConfigurationconfigprotected KafkaConsumer<?,?>consumerprotected KafkaLogginglogprotected Map<org.apache.kafka.common.TopicPartition,ProcessingState<?>>processingStateMapprotected BiConsumer<Throwable,Boolean>reportFailure-
Fields inherited from class io.smallrye.reactive.messaging.kafka.commit.ContextHolder
context, vertx
-
-
Constructor Summary
Constructors Constructor Description KafkaCheckpointCommit(io.vertx.mutiny.core.Vertx vertx, KafkaConnectorIncomingConfiguration config, KafkaConsumer<?,?> consumer, BiConsumer<Throwable,Boolean> reportFailure, int defaultTimeout)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract io.smallrye.mutiny.Uni<ProcessingState<?>>fetchProcessingState(org.apache.kafka.common.TopicPartition partition)<K,V>
io.smallrye.mutiny.Uni<Void>handle(IncomingKafkaRecord<K,V> record)Handle message acknowledgmentvoidpartitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> partitions)Called on partitions assigned on Kafka rebalance listenervoidpartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)Called on partitions revokd on Kafka rebalance listenerprotected abstract io.smallrye.mutiny.Uni<Void>persistProcessingState(org.apache.kafka.common.TopicPartition partition, ProcessingState<?> state)<K,V>
io.smallrye.mutiny.Uni<IncomingKafkaRecord<K,V>>received(IncomingKafkaRecord<K,V> record)Called on message received but before calling the processing function.voidterminate(boolean graceful)Called on channel shutdown-
Methods inherited from class io.smallrye.reactive.messaging.kafka.commit.ContextHolder
capture, capture, getContext, getTimeoutInMillis, runOnContext, runOnContextAndAwait
-
-
-
-
Field Detail
-
log
protected KafkaLogging log
-
processingStateMap
protected final Map<org.apache.kafka.common.TopicPartition,ProcessingState<?>> processingStateMap
-
config
protected final KafkaConnectorIncomingConfiguration config
-
consumer
protected final KafkaConsumer<?,?> consumer
-
reportFailure
protected final BiConsumer<Throwable,Boolean> reportFailure
-
-
Constructor Detail
-
KafkaCheckpointCommit
public KafkaCheckpointCommit(io.vertx.mutiny.core.Vertx vertx, KafkaConnectorIncomingConfiguration config, KafkaConsumer<?,?> consumer, BiConsumer<Throwable,Boolean> reportFailure, int defaultTimeout)
-
-
Method Detail
-
received
public <K,V> io.smallrye.mutiny.Uni<IncomingKafkaRecord<K,V>> received(IncomingKafkaRecord<K,V> record)
Description copied from interface:KafkaCommitHandlerCalled on message received but before calling the processing function. ReturnedUniallows chaining asynchronous actions before message processing.- Specified by:
receivedin interfaceKafkaCommitHandler- Type Parameters:
K- type of record keyV- type of record value- Parameters:
record- incoming Kafka record- Returns:
- the
Uniyielding the received record
-
handle
public <K,V> io.smallrye.mutiny.Uni<Void> handle(IncomingKafkaRecord<K,V> record)
Description copied from interface:KafkaCommitHandlerHandle message acknowledgment- Specified by:
handlein interfaceKafkaCommitHandler- Type Parameters:
K- type of record keyV- type of record value- Parameters:
record- incoming Kafka record- Returns:
- a completion stage completed when the message is acknowledged.
-
terminate
public void terminate(boolean graceful)
Description copied from interface:KafkaCommitHandlerCalled on channel shutdown- Specified by:
terminatein interfaceKafkaCommitHandler- Parameters:
graceful-trueif it is a graceful shutdown
-
partitionsAssigned
public void partitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> partitions)
Description copied from interface:KafkaCommitHandlerCalled on partitions assigned on Kafka rebalance listener- Specified by:
partitionsAssignedin interfaceKafkaCommitHandler- Parameters:
partitions- assigned partitions
-
partitionsRevoked
public void partitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)
Description copied from interface:KafkaCommitHandlerCalled on partitions revokd on Kafka rebalance listener- Specified by:
partitionsRevokedin interfaceKafkaCommitHandler- Parameters:
partitions- revoked partitions
-
fetchProcessingState
protected abstract io.smallrye.mutiny.Uni<ProcessingState<?>> fetchProcessingState(org.apache.kafka.common.TopicPartition partition)
-
persistProcessingState
protected abstract io.smallrye.mutiny.Uni<Void> persistProcessingState(org.apache.kafka.common.TopicPartition partition, ProcessingState<?> state)
-
-