Class WebSocketEventStoreClient

java.lang.Object
io.fluxzero.sdk.common.websocket.AbstractWebsocketClient
io.fluxzero.sdk.persisting.eventsourcing.client.WebSocketEventStoreClient
All Implemented Interfaces:
WebsocketEndpoint, EventStoreClient, AutoCloseable

public class WebSocketEventStoreClient extends AbstractWebsocketClient implements EventStoreClient
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. The aggregate-history byte setting in WebSocketClient.ClientConfig independently bounds the cumulative serialized event-payload bytes requested per page. An individually oversized first event is still returned so paging can advance.

End users rarely interact with this client directly. Instead, they typically use higher-level abstractions such as EventStore or AggregateRepository.

See Also:
  • Constructor Details

    • WebSocketEventStoreClient

      public WebSocketEventStoreClient(String endPointUrl, WebSocketClient client)
      Creates a new WebSocketEventStoreClient with a default batch size of 8192.
      Parameters:
      endPointUrl - The URL to the Fluxzero Runtime event sourcing endpoint.
      client - The WebSocket client instance.
    • WebSocketEventStoreClient

      public WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client)
      Creates a new WebSocketEventStoreClient with 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:
      storeEvents in interface EventStoreClient
      Parameters:
      aggregateId - The aggregate ID.
      events - Events to store.
      storeOnly - If true, 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:
      getEvents in interface EventStoreClient
      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

      public CompletableFuture<Void> updateRelationships(UpdateRelationships request)
      Sends a request to update the relationships of an entity or aggregate.
      Specified by:
      updateRelationships in interface EventStoreClient
      Parameters:
      request - The update request.
      Returns:
      A future that completes when the operation is acknowledged.
    • repairRelationships

      public CompletableFuture<Void> repairRelationships(RepairRelationships request)
      Sends a request to repair relationships for a specific entity.
      Specified by:
      repairRelationships in interface EventStoreClient
      Parameters:
      request - The repair request.
      Returns:
      A future that completes when the repair is done.
    • getAggregateIds

      public Map<String,String> getAggregateIds(GetAggregateIds request)
      Retrieves a map of aggregate IDs associated with a given entity, using a GetAggregateIds request.
      Specified by:
      getAggregateIds in interface EventStoreClient
      Parameters:
      request - The request containing filtering options.
      Returns:
      A map of aggregate IDs referencing the target entity.
    • getRelationships

      public List<Relationship> getRelationships(GetRelationships request)
      Retrieves all relationships for a given entity, using a GetRelationships request.
      Specified by:
      getRelationships in interface EventStoreClient
      Parameters:
      request - The request containing filter parameters.
      Returns:
      A list of matching relationships.
    • deleteEvents

      public CompletableFuture<Void> deleteEvents(String aggregateId, Guarantee guarantee)
      Sends a delete command for the event stream of the specified aggregate.
      Specified by:
      deleteEvents in interface EventStoreClient
      Parameters:
      aggregateId - The aggregate ID.
      guarantee - The guarantee to apply.
      Returns:
      A future that completes when deletion is acknowledged.