Class LocalTrackingClient
java.lang.Object
io.fluxzero.sdk.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 Fluxzero backend. It uses local data structures to emulate:
- A
MessageStoreto persist serialized messages - A
PositionStoreto track consumer offsets - A
TrackingStrategyto emulate segment claims and batch fetch behavior
Use Cases
- Unit tests or integration tests involving command/event/query handling
- Local development without using Fluxzero Runtime as a backend
- Custom tooling that simulates tracking or playback behavior
Behavior
- Messages are stored in memory and may be optionally expired using
messageExpirationif 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.CUSTOMorMessageType.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.voidclose()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 availableMessageBatchfor 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 typeToccurs.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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HasMessageStore
getMessageStoreMethods inherited from interface TrackingClient
disconnectTracker, getMessageType, getTopic, readAndWait, resetPosition, storePosition
-
Constructor Details
-
LocalTrackingClient
-
LocalTrackingClient
-
LocalTrackingClient
-
-
Method Details
-
registerMonitor
Description copied from interface:MonitoredRegisters a monitor that will be notified when an activity of typeToccurs.- Specified by:
registerMonitorin interfaceMonitored<List<SerializedMessage>>- Parameters:
monitor- the callback to invoke with each observed value- Returns:
- a
Registrationthat can be used to cancel the monitoring
-
append
Description copied from interface:GatewayClientAppend the given messages to the gateway, applying the given deliveryGuarantee.- Specified by:
appendin 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
CompletableFuturethat completes when the append operation is successful or fails if delivery fails
-
setRetentionTime
Description copied from interface:GatewayClientSet 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:
setRetentionTimein interfaceGatewayClient- Parameters:
duration- the new retention durationguarantee- the delivery guarantee to apply to the update operation- Returns:
- a
CompletableFuturethat completes once the retention setting is updated
-
read
public CompletableFuture<MessageBatch> read(String trackerId, Long lastIndex, ConsumerConfiguration config) Description copied from interface:TrackingClientAsynchronously reads the next availableMessageBatchfor a given tracker.- Specified by:
readin 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
CompletableFuturethat completes with the next batch of messages
-
readFromIndex
Description copied from interface:TrackingClientFetches 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:
readFromIndexin 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:TrackingClientClaims a processing segment for the given tracker.Segments are used to partition the message log among multiple tracker threads for parallel processing.
- Specified by:
claimSegmentin 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
CompletableFutureresolving to the result of the claim
-
storePosition
public CompletableFuture<Void> storePosition(String consumer, int[] segment, long lastIndex, Guarantee guarantee) Description copied from interface:TrackingClientStores the last successfully processed position for a consumer with a specific delivery guarantee.- Specified by:
storePositionin 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:TrackingClientResets the consumer's tracking position to a given index with a specific delivery guarantee.- Specified by:
resetPositionin 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:TrackingClientReturns the current committed tracking position for the given consumer.- Specified by:
getPositionin 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:TrackingClientDisconnects the specified tracker from its segment with the specified delivery guarantee.- Specified by:
disconnectTrackerin 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:TrackingClientCloses any open resources associated with this client.Once closed, the client should no longer be used to fetch or commit tracking state.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceGatewayClient- Specified by:
closein interfaceTrackingClient
-