Interface TrackingClient
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
CachingTrackingClient
,LocalEventStoreClient
,LocalSchedulingClient
,LocalTrackingClient
,WebsocketTrackingClient
A TrackingClient
is responsible for retrieving message batches, claiming processing segments, and managing
tracking positions for a named consumer. Implementations typically include:
- An in-memory version for testing scenarios
- A WebSocket-backed implementation for connecting to the Flux Capacitor platform
Each message type (e.g., command, event, query) is backed by its own TrackingClient
instance,
allowing independent consumption streams and tracking state.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionclaimSegment
(String trackerId, Long lastIndex, ConsumerConfiguration config) Claims a processing segment for the given tracker.void
close()
Closes any open resources associated with this client.default CompletableFuture
<Void> disconnectTracker
(String consumer, String trackerId, boolean sendFinalEmptyBatch) Disconnects the specified tracker from its segment and optionally sends an empty final batch.disconnectTracker
(String consumer, String trackerId, boolean sendFinalEmptyBatch, Guarantee guarantee) Disconnects the specified tracker from its segment with the specified delivery guarantee.Returns theMessageType
(e.g., COMMAND, EVENT, QUERY) associated with this tracking client.getPosition
(String consumer) Returns the current committed tracking position for the given consumer.getTopic()
Returns the topic associated with this tracking client.read
(String trackerId, Long lastIndex, ConsumerConfiguration trackingConfiguration) Asynchronously reads the next availableMessageBatch
for a given tracker.default MessageBatch
readAndWait
(String trackerId, Long lastIndex, ConsumerConfiguration configuration) Reads the next availableMessageBatch
for the given tracker and blocks until messages are available.readFromIndex
(long minIndex, int maxSize) Fetches messages starting from the given index up to the provided max size.default CompletableFuture
<Void> resetPosition
(String consumer, long lastIndex) Resets the consumer's tracking position to a given index.resetPosition
(String consumer, long lastIndex, Guarantee guarantee) Resets the consumer's tracking position to a given index with a specific delivery guarantee.default CompletableFuture
<Void> storePosition
(String consumer, int[] segment, long lastIndex) Stores the last successfully processed position for a consumer.storePosition
(String consumer, int[] segment, long lastIndex, Guarantee guarantee) Stores the last successfully processed position for a consumer with a specific delivery guarantee.
-
Method Details
-
readAndWait
default MessageBatch readAndWait(String trackerId, Long lastIndex, ConsumerConfiguration configuration) Reads the next availableMessageBatch
for the given tracker and blocks until messages are available.This is a convenience method that synchronously waits for
read(java.lang.String, java.lang.Long, io.fluxcapacitor.javaclient.tracking.ConsumerConfiguration)
to complete.- Parameters:
trackerId
- the unique identifier of the tracker requesting messageslastIndex
- the last successfully processed indexconfiguration
- the consumer configuration that determines segment, filters, and batch settings- Returns:
- the next available message batch (may be empty if disconnected)
-
read
CompletableFuture<MessageBatch> read(String trackerId, Long lastIndex, ConsumerConfiguration trackingConfiguration) Asynchronously reads the next availableMessageBatch
for a given tracker.- Parameters:
trackerId
- the unique ID for the tracker thread requesting messageslastIndex
- the last index successfully handled by this trackertrackingConfiguration
- the full configuration for the consumer- Returns:
- a
CompletableFuture
that completes with the next batch of messages
-
readFromIndex
Fetches messages starting from the given index up to the provided max size.This method bypasses consumer configurations and is primarily used for diagnostics or reprocessing.
- Parameters:
minIndex
- the starting index (inclusive)maxSize
- the maximum number of messages to retrieve- Returns:
- a list of serialized messages starting at the given index
-
claimSegment
CompletableFuture<ClaimSegmentResult> claimSegment(String trackerId, Long lastIndex, ConsumerConfiguration config) Claims a processing segment for the given tracker.Segments are used to partition the message log among multiple tracker threads for parallel processing.
- Parameters:
trackerId
- the unique identifier of the tracker attempting to claim a segmentlastIndex
- the tracker's last successfully processed indexconfig
- the full consumer configuration- Returns:
- a
CompletableFuture
resolving to the result of the claim
-
storePosition
Stores the last successfully processed position for a consumer.Default implementation uses
Guarantee.STORED
as the delivery guarantee.- Parameters:
consumer
- the name of the consumersegment
- the segment the tracker is processinglastIndex
- the index up to which messages have been handled- Returns:
- a future indicating completion
-
storePosition
CompletableFuture<Void> storePosition(String consumer, int[] segment, long lastIndex, Guarantee guarantee) Stores the last successfully processed position for a consumer with a specific delivery guarantee.- Parameters:
consumer
- the name of the consumersegment
- the segment the tracker is processinglastIndex
- the last message index processedguarantee
- delivery guarantee (e.g., STORED, SENT)- Returns:
- a future indicating completion
-
resetPosition
Resets the consumer's tracking position to a given index.This is often used for replay, diagnostics, or recovery scenarios. Uses
Guarantee.STORED
by default.- Parameters:
consumer
- the name of the consumerlastIndex
- the new index to start from- Returns:
- a future indicating completion
-
resetPosition
Resets the consumer's tracking position to a given index with a specific delivery guarantee.- Parameters:
consumer
- the name of the consumerlastIndex
- the new index to start fromguarantee
- the delivery guarantee- Returns:
- a future indicating completion
-
getPosition
Returns the current committed tracking position for the given consumer.- Parameters:
consumer
- the name of the consumer- Returns:
- the last known committed position
-
disconnectTracker
default CompletableFuture<Void> disconnectTracker(String consumer, String trackerId, boolean sendFinalEmptyBatch) Disconnects the specified tracker from its segment and optionally sends an empty final batch.Default implementation uses
Guarantee.SENT
.- Parameters:
consumer
- the name of the consumer grouptrackerId
- the ID of the tracker thread being disconnectedsendFinalEmptyBatch
- whether to send an empty batch to flush tracking state- Returns:
- a future indicating disconnection
-
disconnectTracker
CompletableFuture<Void> disconnectTracker(String consumer, String trackerId, boolean sendFinalEmptyBatch, Guarantee guarantee) Disconnects the specified tracker from its segment with the specified delivery guarantee.- Parameters:
consumer
- the name of the consumer grouptrackerId
- the ID of the tracker thread being disconnectedsendFinalEmptyBatch
- whether to send a final empty batch to commit stateguarantee
- the delivery guarantee to use- Returns:
- a future indicating disconnection
-
getMessageType
MessageType getMessageType()Returns theMessageType
(e.g., COMMAND, EVENT, QUERY) associated with this tracking client.- Returns:
- the message type
-
getTopic
String getTopic()Returns the topic associated with this tracking client.This is applicable only when
getMessageType()
isMessageType.DOCUMENT
orMessageType.CUSTOM
, where messages are organized into named topics beyond the standard type-based categorization.For other
MessageType
s (e.g.,COMMAND
,EVENT
), the concept of a topic is implicit and not required for tracking.- Returns:
- the topic name, or
null
if not applicable for the message type
-
close
void close()Closes any open resources associated with this client.Once closed, the client should no longer be used to fetch or commit tracking state.
- Specified by:
close
in interfaceAutoCloseable
-