Interface CheckpointMetadata<T>
-
- Type Parameters:
T
- type of the processing state
- All Known Implementing Classes:
DefaultCheckpointMetadata
public interface CheckpointMetadata<T>
Checkpoint metadata type for injecting state checkpointing interactions into received messages. This allows accessing the current processing state restored from the state store, and produce the next state. The next state can be saved locally or persisted into the external store.A sample processing method with checkpointing would be:
@Incoming("in") public CompletionStage<Void> process(Message<String> msg) { CheckpointMetadata<Integer> checkpoint = CheckpointMetadata.fromMessage(msg); if (checkpoint != null) { checkpoint.transform(0, current -> current + msg.getPayload()); } return CompletableFuture.completed(null); }
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <S> CheckpointMetadata<S>
fromMessage(org.eclipse.microprofile.reactive.messaging.Message<?> message)
ProcessingState<T>
getCurrent()
ProcessingState<T>
getNext()
long
getRecordOffset()
org.apache.kafka.common.TopicPartition
getTopicPartition()
boolean
isPersistOnAck()
T
setNext(T state)
Set the next processing state to the given state, associated with the current record offset + 1.T
setNext(T state, boolean persistOnAck)
Set the next processing state to the given state, associated with the current record offset + 1.T
transform(Supplier<T> initialStateSupplier, Function<T,T> transformation)
Seetransform(Supplier, Function, boolean)
The state will not be persisted on message acknowledgement.T
transform(Supplier<T> initialStateSupplier, Function<T,T> transformation, boolean persistOnAck)
Apply the transformation to the current state, if a previous state doesn't exist, start the transformation from the supplied initial state.T
transform(T initialState, Function<T,T> transformation)
Seetransform(Supplier, Function, boolean)
The state will not be persisted on message acknowledgement.T
transform(T initialState, Function<T,T> transformation, boolean persistOnAck)
-
-
-
Method Detail
-
fromMessage
static <S> CheckpointMetadata<S> fromMessage(org.eclipse.microprofile.reactive.messaging.Message<?> message)
-
getTopicPartition
org.apache.kafka.common.TopicPartition getTopicPartition()
- Returns:
- the topic-partition of this record
-
getRecordOffset
long getRecordOffset()
- Returns:
- the offset of this record
-
isPersistOnAck
boolean isPersistOnAck()
- Returns:
true
if the processing state will be persisted on message acknowledgement
-
getCurrent
ProcessingState<T> getCurrent()
- Returns:
- the current processing state
-
getNext
ProcessingState<T> getNext()
- Returns:
- the next processing state set during this processing
-
setNext
T setNext(T state, boolean persistOnAck)
Set the next processing state to the given state, associated with the current record offset + 1.- Parameters:
state
- the next statepersistOnAck
- Iftrue
then the state will be persisted on message acknowledgement- Returns:
- the previous state
-
setNext
T setNext(T state)
Set the next processing state to the given state, associated with the current record offset + 1. The state will not be persisted on message acknowledgement.- Parameters:
state
- the next state- Returns:
- the previous state
-
transform
T transform(Supplier<T> initialStateSupplier, Function<T,T> transformation, boolean persistOnAck)
Apply the transformation to the current state, if a previous state doesn't exist, start the transformation from the supplied initial state. The state will be associated with the current record offset + 1.- Parameters:
initialStateSupplier
- if no previous state does exist, start the transformation from this state.transformation
- the transformation functionpersistOnAck
- Iftrue
then the state will be persisted on message acknowledgement- Returns:
- the previous state
-
transform
T transform(T initialState, Function<T,T> transformation, boolean persistOnAck)
- Parameters:
initialState
- if no previous state does exist, start the transformation from this state.transformation
- the transformation functionpersistOnAck
- Iftrue
then the state will be persisted on message acknowledgement- Returns:
- the previous state
-
transform
T transform(Supplier<T> initialStateSupplier, Function<T,T> transformation)
Seetransform(Supplier, Function, boolean)
The state will not be persisted on message acknowledgement.- Parameters:
initialStateSupplier
- if no previous state does exist, start the transformation from this state.transformation
- the transformation function- Returns:
- the previous state
-
transform
T transform(T initialState, Function<T,T> transformation)
Seetransform(Supplier, Function, boolean)
The state will not be persisted on message acknowledgement.- Parameters:
initialState
- if no previous state does exist, start the transformation from this state.transformation
- the transformation function- Returns:
- the previous state
-
-