Class WebSocketEventStoreClient
java.lang.Object
io.fluxzero.sdk.common.websocket.AbstractWebsocketClient
io.fluxzero.sdk.persisting.eventsourcing.client.WebSocketEventStoreClient
- All Implemented Interfaces:
EventStoreClient, AutoCloseable
WebSocket-based implementation of the
EventStoreClient, enabling interaction with the Fluxzero Runtime's event
store via a persistent WebSocket connection.
This implementation supports:
- Storing events for event-sourced aggregates
- Efficient, paginated retrieval of aggregate event streams
- Deleting aggregate event streams
- Maintaining aggregate/entity relationships
The fetchBatchSize setting controls how many events are fetched per paginated request when loading
an aggregate's event history. This ensures efficient memory usage while still supporting large aggregates.
End users rarely interact with this client directly. Instead, they typically use higher-level abstractions
such as EventStore or
AggregateRepository.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractWebsocketClient
AbstractWebsocketClient.PingRegistration, AbstractWebsocketClient.WebSocketRequest -
Field Summary
Fields inherited from class AbstractWebsocketClient
defaultObjectMapper, defaultWebSocketContainer -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketEventStoreClient(String endPointUrl, WebSocketClient client) Creates a newWebSocketEventStoreClientwith a default batch size of 8192.WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client) Creates a newWebSocketEventStoreClientwith a specified batch size.WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client, boolean sendMetrics) Constructs the WebSocket client with full customization. -
Method Summary
Modifier and TypeMethodDescriptiondeleteEvents(String aggregateId, Guarantee guarantee) Sends a delete command for the event stream of the specified aggregate.getAggregateIds(GetAggregateIds request) Retrieves a map of aggregate IDs associated with a given entity, using aGetAggregateIdsrequest.Retrieves events for a specific aggregate starting after a given sequence number, optionally limiting the result size.getRelationships(GetRelationships request) Retrieves all relationships for a given entity, using aGetRelationshipsrequest.repairRelationships(RepairRelationships request) Sends a request to repair relationships for a specific entity.storeEvents(String aggregateId, List<SerializedMessage> events, boolean storeOnly, Guarantee guarantee) Stores events for a specific aggregate, with control over store-only mode and delivery guarantee.updateRelationships(UpdateRelationships request) Sends a request to update the relationships of an entity or aggregate.Methods inherited from class AbstractWebsocketClient
abort, close, close, handleResult, metricsMetadata, onClose, onError, onMessage, onOpen, onPong, retryOutstandingRequests, schedulePing, send, sendAndWait, sendCommand, sendPing, toString, tryPublishMetricsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface EventStoreClient
close, deleteEvents, getAggregatesFor, getEvents, getEvents, getRelationships, storeEvents
-
Constructor Details
-
WebSocketEventStoreClient
Creates a newWebSocketEventStoreClientwith a default batch size of 8192.- Parameters:
endPointUrl- The URL to the Fluxzero Runtime event sourcing endpoint.client- The WebSocket client instance.
-
WebSocketEventStoreClient
Creates a newWebSocketEventStoreClientwith a specified batch size.- Parameters:
endPointUri- The URI to the event store endpoint.fetchBatchSize- Maximum number of events to retrieve per page.client- The WebSocket client.
-
WebSocketEventStoreClient
public WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client, boolean sendMetrics) Constructs the WebSocket client with full customization.- Parameters:
endPointUri- URI of the event sourcing endpoint.fetchBatchSize- The size of event batches fetched from the server.client- The WebSocket client.sendMetrics- Whether to send metrics to the Fluxzero Runtime.
-
-
Method Details
-
storeEvents
public CompletableFuture<Void> storeEvents(String aggregateId, List<SerializedMessage> events, boolean storeOnly, Guarantee guarantee) Stores events for a specific aggregate, with control over store-only mode and delivery guarantee.- Specified by:
storeEventsin interfaceEventStoreClient- Parameters:
aggregateId- The aggregate ID.events- Events to store.storeOnly- Iftrue, events will not be published.guarantee- The guarantee level for this operation.- Returns:
- A future representing completion of the store operation.
-
getEvents
public AggregateEventStream<SerializedMessage> getEvents(String aggregateId, long lastSequenceNumber, int maxSize) Retrieves events for a specific aggregate starting after a given sequence number, optionally limiting the result size.- Specified by:
getEventsin interfaceEventStoreClient- Parameters:
aggregateId- The aggregate ID.lastSequenceNumber- Sequence number to resume after.maxSize- Maximum number of events to return (or -1 for unlimited).- Returns:
- A stream of serialized events.
-
updateRelationships
Sends a request to update the relationships of an entity or aggregate.- Specified by:
updateRelationshipsin interfaceEventStoreClient- Parameters:
request- The update request.- Returns:
- A future that completes when the operation is acknowledged.
-
repairRelationships
Sends a request to repair relationships for a specific entity.- Specified by:
repairRelationshipsin interfaceEventStoreClient- Parameters:
request- The repair request.- Returns:
- A future that completes when the repair is done.
-
getAggregateIds
Retrieves a map of aggregate IDs associated with a given entity, using aGetAggregateIdsrequest.- Specified by:
getAggregateIdsin interfaceEventStoreClient- Parameters:
request- The request containing filtering options.- Returns:
- A map of aggregate IDs referencing the target entity.
-
getRelationships
Retrieves all relationships for a given entity, using aGetRelationshipsrequest.- Specified by:
getRelationshipsin interfaceEventStoreClient- Parameters:
request- The request containing filter parameters.- Returns:
- A list of matching relationships.
-
deleteEvents
Sends a delete command for the event stream of the specified aggregate.- Specified by:
deleteEventsin interfaceEventStoreClient- Parameters:
aggregateId- The aggregate ID.guarantee- The guarantee to apply.- Returns:
- A future that completes when deletion is acknowledged.
-