Class LocalTrackingClient
java.lang.Object
io.fluxcapacitor.javaclient.tracking.client.LocalTrackingClient
- All Implemented Interfaces:
Monitored<List<SerializedMessage>>
,HasMessageStore
,GatewayClient
,TrackingClient
,AutoCloseable
- Direct Known Subclasses:
LocalEventStoreClient
,LocalSchedulingClient
public class LocalTrackingClient
extends Object
implements TrackingClient, GatewayClient, HasMessageStore
In-memory implementation of the
TrackingClient
and GatewayClient
interfaces, designed for
local-only or test-time usage.
This client simulates message tracking behavior without requiring a live Flux Capacitor backend. It uses local data structures to emulate:
- A
MessageStore
to persist serialized messages - A
PositionStore
to track consumer offsets - A
TrackingStrategy
to emulate segment claims and batch fetch behavior
Use Cases
- Unit tests or integration tests involving command/event/query handling
- Local development without a Flux backend connection
- Custom tooling that simulates tracking or playback behavior
Behavior
- Messages are stored in memory and may be optionally expired using
messageExpiration
if configured - Tracks per-consumer positions independently via an in-memory position store
- Implements segment claiming and disconnection logic to simulate parallel consumer behavior
- Supports custom topics for
MessageType.CUSTOM
orMessageType.DOCUMENT
Example
TrackingClient testClient = new LocalTrackingClient(MessageType.EVENT, "test-topic", Duration.ofMinutes(10));
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLocalTrackingClient
(MessageType messageType, String topic, Duration messageExpiration) LocalTrackingClient
(MessageStore messageStore, MessageType messageType) LocalTrackingClient
(MessageStore messageStore, MessageType messageType, String topic) -
Method Summary
Modifier and TypeMethodDescriptionappend
(Guarantee guarantee, SerializedMessage... messages) Append the given messages to the gateway, applying the given deliveryGuarantee
.claimSegment
(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.read
(String trackerId, Long lastIndex, ConsumerConfiguration config) 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.registerMonitor
(Consumer<List<SerializedMessage>> monitor) Registers a monitor that will be notified when an activity of typeT
occurs.resetPosition
(String consumer, long lastIndex, Guarantee guarantee) Resets the consumer's tracking position to a given index with a specific delivery guarantee.setRetentionTime
(Duration duration, Guarantee guarantee) Set a new retention duration for the underlying gateway's message log.storePosition
(String consumer, int[] segment, long lastIndex, Guarantee guarantee) Stores the last successfully processed position for a consumer with a specific delivery guarantee.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.tracking.HasMessageStore
getMessageStore
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.client.TrackingClient
disconnectTracker, getMessageType, getTopic, readAndWait, resetPosition, storePosition
-
Constructor Details
-
LocalTrackingClient
-
LocalTrackingClient
-
LocalTrackingClient
-
-
Method Details
-
registerMonitor
Description copied from interface:Monitored
Registers a monitor that will be notified when an activity of typeT
occurs.- Specified by:
registerMonitor
in interfaceMonitored<List<SerializedMessage>>
- Parameters:
monitor
- the callback to invoke with each observed value- Returns:
- a
Registration
that can be used to cancel the monitoring
-
append
Description copied from interface:GatewayClient
Append the given messages to the gateway, applying the given deliveryGuarantee
.- Specified by:
append
in interfaceGatewayClient
- Parameters:
guarantee
- the delivery guarantee that should be respected (e.g. at-most-once, at-least-once)messages
- one or more serialized messages to append- Returns:
- a
CompletableFuture
that completes when the append operation is successful or fails if delivery fails
-
setRetentionTime
Description copied from interface:GatewayClient
Set a new retention duration for the underlying gateway's message log.The retention setting determines how long messages in this log are retained by the system, after which they may be evicted or deleted depending on the platform policy.
- Specified by:
setRetentionTime
in interfaceGatewayClient
- Parameters:
duration
- the new retention durationguarantee
- the delivery guarantee to apply to the update operation- Returns:
- a
CompletableFuture
that completes once the retention setting is updated
-
read
public CompletableFuture<MessageBatch> read(String trackerId, Long lastIndex, ConsumerConfiguration config) 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 trackerconfig
- the full configuration for the consumer- Returns:
- a
CompletableFuture
that completes with the next batch of messages
-
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
-
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
-
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
-
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 interfaceGatewayClient
- Specified by:
close
in interfaceTrackingClient
-