Class StateStore<T>
- java.lang.Object
-
- io.smallrye.reactive.messaging.kafka.commit.StateStore<T>
-
- Type Parameters:
T
- type of the processing state
public class StateStore<T> extends Object
State store metadata type for injecting state store 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) { StateStore<Integer> stateStore = StateStore.fromMessage(msg); if (stateStore != null) { stateStore.transformAndStoreOnAck(0, current -> current + msg.getPayload()); } return CompletableFuture.completed(null); }
-
-
Field Summary
Fields Modifier and Type Field Description protected KafkaLogging
log
-
Constructor Summary
Constructors Constructor Description StateStore(org.apache.kafka.common.TopicPartition topicPartition, long recordOffset, Supplier<ProcessingState<T>> stateSupplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <S> StateStore<S>
fromMessage(org.eclipse.microprofile.reactive.messaging.Message<?> message)
Optional<ProcessingState<T>>
getCurrent()
Optional<ProcessingState<T>>
getNext()
static <S> ProcessingState<S>
getProcessingState(org.eclipse.microprofile.reactive.messaging.Message<?> message)
long
getRecordOffset()
org.apache.kafka.common.TopicPartition
getTopicPartition()
boolean
isPersist()
static boolean
isPersist(org.eclipse.microprofile.reactive.messaging.Message<?> message)
T
storeLocal(T state)
T
storeLocal(T state, long offset)
T
storeOnAck(T state)
T
storeOnAck(T state, long offset)
T
transformAndStoreLocal(T initialState, Function<T,T> transformation)
T
transformAndStoreOnAck(T initialState, Function<T,T> transformation)
-
-
-
Field Detail
-
log
protected KafkaLogging log
-
-
Constructor Detail
-
StateStore
public StateStore(org.apache.kafka.common.TopicPartition topicPartition, long recordOffset, Supplier<ProcessingState<T>> stateSupplier)
-
-
Method Detail
-
getProcessingState
public static <S> ProcessingState<S> getProcessingState(org.eclipse.microprofile.reactive.messaging.Message<?> message)
-
isPersist
public static boolean isPersist(org.eclipse.microprofile.reactive.messaging.Message<?> message)
-
fromMessage
public static <S> StateStore<S> fromMessage(org.eclipse.microprofile.reactive.messaging.Message<?> message)
-
getTopicPartition
public org.apache.kafka.common.TopicPartition getTopicPartition()
-
getRecordOffset
public long getRecordOffset()
-
isPersist
public boolean isPersist()
-
getCurrent
public Optional<ProcessingState<T>> getCurrent()
-
getNext
public Optional<ProcessingState<T>> getNext()
-
transformAndStoreLocal
public T transformAndStoreLocal(T initialState, Function<T,T> transformation)
-
-