Class WebsocketTrackingClient

java.lang.Object
io.fluxcapacitor.javaclient.common.websocket.AbstractWebsocketClient
io.fluxcapacitor.javaclient.tracking.client.WebsocketTrackingClient
All Implemented Interfaces:
TrackingClient, AutoCloseable

public class WebsocketTrackingClient extends AbstractWebsocketClient implements TrackingClient
WebSocket-based implementation of the 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:
  • Constructor Details

  • Method Details

    • read

      public CompletableFuture<MessageBatch> read(String trackerId, Long lastIndex, ConsumerConfiguration configuration)
      Description copied from interface: TrackingClient
      Asynchronously reads the next available MessageBatch for a given tracker.
      Specified by:
      read in interface TrackingClient
      Parameters:
      trackerId - the unique ID for the tracker thread requesting messages
      lastIndex - the last index successfully handled by this tracker
      configuration - 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 interface TrackingClient
      Parameters:
      trackerId - the unique identifier of the tracker attempting to claim a segment
      lastIndex - the tracker's last successfully processed index
      config - the full consumer configuration
      Returns:
      a CompletableFuture resolving to the result of the claim
    • readFromIndex

      public List<SerializedMessage> readFromIndex(long minIndex, int maxSize)
      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 interface TrackingClient
      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 interface TrackingClient
      Parameters:
      consumer - the name of the consumer
      segment - the segment the tracker is processing
      lastIndex - the last message index processed
      guarantee - delivery guarantee (e.g., STORED, SENT)
      Returns:
      a future indicating completion
    • resetPosition

      public CompletableFuture<Void> resetPosition(String consumer, long lastIndex, Guarantee guarantee)
      Description copied from interface: TrackingClient
      Resets the consumer's tracking position to a given index with a specific delivery guarantee.
      Specified by:
      resetPosition in interface TrackingClient
      Parameters:
      consumer - the name of the consumer
      lastIndex - the new index to start from
      guarantee - the delivery guarantee
      Returns:
      a future indicating completion
    • getPosition

      public Position getPosition(String consumer)
      Description copied from interface: TrackingClient
      Returns the current committed tracking position for the given consumer.
      Specified by:
      getPosition in interface TrackingClient
      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 interface TrackingClient
      Parameters:
      consumer - the name of the consumer group
      trackerId - the ID of the tracker thread being disconnected
      sendFinalEmptyBatch - whether to send a final empty batch to commit state
      guarantee - the delivery guarantee to use
      Returns:
      a future indicating disconnection
    • metricsMetadata

      protected Metadata metricsMetadata()
      Overrides:
      metricsMetadata in class AbstractWebsocketClient
    • 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 interface AutoCloseable
      Specified by:
      close in interface TrackingClient
      Overrides:
      close in class AbstractWebsocketClient
    • toString

      public String toString()
      Overrides:
      toString in class AbstractWebsocketClient