Class WebsocketTrackingClient
- All Implemented Interfaces:
TrackingClient
,AutoCloseable
TrackingClient
that connects to the Flux platform.
All tracking-related operations—including reading messages, claiming segments, storing/resetting positions, and disconnecting trackers—are performed via a standardized WebSocket protocol with the Flux platform.
This is the default production implementation used in deployed applications to track message streams such as commands, queries, events, and other custom message types.
Requires an active WebSocket connection to the Flux platform’s tracking service.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class io.fluxcapacitor.javaclient.common.websocket.AbstractWebsocketClient
AbstractWebsocketClient.PingRegistration, AbstractWebsocketClient.WebSocketRequest
-
Field Summary
Fields inherited from class io.fluxcapacitor.javaclient.common.websocket.AbstractWebsocketClient
defaultObjectMapper, defaultWebSocketContainer
-
Constructor Summary
ConstructorsConstructorDescriptionWebsocketTrackingClient
(String endPointUrl, WebSocketClient client, MessageType type, String topic) WebsocketTrackingClient
(URI endPointUri, WebSocketClient client, MessageType type, String topic, boolean sendMetrics) -
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.disconnectTracker
(String consumer, String trackerId, boolean sendFinalEmptyBatch, Guarantee guarantee) Disconnects the specified tracker from its segment with the specified delivery guarantee.getPosition
(String consumer) Returns the current committed tracking position for the given consumer.protected Metadata
read
(String trackerId, Long lastIndex, ConsumerConfiguration configuration) Asynchronously reads the next availableMessageBatch
for a given tracker.readFromIndex
(long minIndex, int maxSize) Fetches messages starting from the given index up to the provided max size.resetPosition
(String consumer, long lastIndex, Guarantee guarantee) Resets the consumer's tracking position to a given index with a specific delivery guarantee.storePosition
(String consumer, int[] segment, long lastIndex, Guarantee guarantee) Stores the last successfully processed position for a consumer with a specific delivery guarantee.toString()
Methods inherited from class io.fluxcapacitor.javaclient.common.websocket.AbstractWebsocketClient
abort, close, handleResult, onClose, onError, onMessage, onOpen, onPong, retryOutstandingRequests, schedulePing, send, sendAndWait, sendCommand, sendPing, tryPublishMetrics
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.client.TrackingClient
disconnectTracker, getMessageType, getTopic, readAndWait, resetPosition, storePosition
-
Constructor Details
-
WebsocketTrackingClient
public WebsocketTrackingClient(String endPointUrl, WebSocketClient client, MessageType type, String topic) -
WebsocketTrackingClient
public WebsocketTrackingClient(URI endPointUri, WebSocketClient client, MessageType type, String topic, boolean sendMetrics)
-
-
Method Details
-
read
public CompletableFuture<MessageBatch> read(String trackerId, Long lastIndex, ConsumerConfiguration configuration) Description copied from interface:TrackingClient
Asynchronously reads the next availableMessageBatch
for a given tracker.- Specified by:
read
in interfaceTrackingClient
- Parameters:
trackerId
- the unique ID for the tracker thread requesting messageslastIndex
- the last index successfully handled by this trackerconfiguration
- the full configuration for the consumer- Returns:
- a
CompletableFuture
that completes with the next batch of messages
-
claimSegment
public CompletableFuture<ClaimSegmentResult> claimSegment(String trackerId, Long lastIndex, ConsumerConfiguration config) Description copied from interface:TrackingClient
Claims a processing segment for the given tracker.Segments are used to partition the message log among multiple tracker threads for parallel processing.
- Specified by:
claimSegment
in interfaceTrackingClient
- 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
-
readFromIndex
Description copied from interface:TrackingClient
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.
- Specified by:
readFromIndex
in interfaceTrackingClient
- 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
-
storePosition
public CompletableFuture<Void> storePosition(String consumer, int[] segment, long lastIndex, Guarantee guarantee) Description copied from interface:TrackingClient
Stores the last successfully processed position for a consumer with a specific delivery guarantee.- Specified by:
storePosition
in interfaceTrackingClient
- 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
Description copied from interface:TrackingClient
Resets the consumer's tracking position to a given index with a specific delivery guarantee.- Specified by:
resetPosition
in interfaceTrackingClient
- Parameters:
consumer
- the name of the consumerlastIndex
- the new index to start fromguarantee
- the delivery guarantee- Returns:
- a future indicating completion
-
getPosition
Description copied from interface:TrackingClient
Returns the current committed tracking position for the given consumer.- Specified by:
getPosition
in interfaceTrackingClient
- Parameters:
consumer
- the name of the consumer- Returns:
- the last known committed position
-
disconnectTracker
public CompletableFuture<Void> disconnectTracker(String consumer, String trackerId, boolean sendFinalEmptyBatch, Guarantee guarantee) Description copied from interface:TrackingClient
Disconnects the specified tracker from its segment with the specified delivery guarantee.- Specified by:
disconnectTracker
in interfaceTrackingClient
- 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
-
metricsMetadata
- Overrides:
metricsMetadata
in classAbstractWebsocketClient
-
close
public void close()Description copied from interface:TrackingClient
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
- Specified by:
close
in interfaceTrackingClient
- Overrides:
close
in classAbstractWebsocketClient
-
toString
- Overrides:
toString
in classAbstractWebsocketClient
-