Class WebsocketGatewayClient

java.lang.Object
io.fluxzero.sdk.common.websocket.AbstractWebsocketClient
io.fluxzero.sdk.publishing.client.WebsocketGatewayClient
All Implemented Interfaces:
GatewayClient, AutoCloseable

public class WebsocketGatewayClient extends AbstractWebsocketClient implements GatewayClient
A GatewayClient implementation that sends serialized messages to the Fluxzero Runtime over a WebSocket connection.

This client is used internally by the Fluxzero framework to publish messages (commands, events, queries, etc.) to the Fluxzero Runtime in a reliable, asynchronous manner. It wraps around a WebSocket transport managed by AbstractWebsocketClient and uses a low-level protocol to dispatch messages as SerializedMessage objects.

Usage: Users typically do not use this class directly. Instead, messages are dispatched using higher-level APIs like CommandGateway or static functions in Fluxzero.

Each WebsocketGatewayClient instance is bound to a specific MessageType and topic. Metrics are optionally sent with each dispatch (enabled by default except for METRICS message gateway clients to prevent infinite recursion).

Features:

  • Supports append operations with configurable delivery Guarantee.
  • Tracks sent messages via registered monitors for observability or auditing purposes.
  • Allows retention time settings to be adjusted on the gateway (if supported).
See Also:
  • Constructor Details

    • WebsocketGatewayClient

      public WebsocketGatewayClient(String endPointUrl, WebSocketClient client, io.fluxzero.common.MessageType type, String topic)
      Constructs a new WebsocketGatewayClient instance using the specified parameters. This constructor initializes the client to connect to a specific WebSocket endpoint for a given message type and topic.

      Metrics messages are enabled unless messageType is MessageType.METRICS.

      Parameters:
      endPointUrl - the WebSocket base endpoint URI to connect to
      client - the WebSocketClient instance used for configuration
      type - the MessageType defining the category of messages this client handles
      topic - the topic associated with the messages handled by this client if MessageType is MessageType.CUSTOM or MessageType.DOCUMENT or null otherwise
    • WebsocketGatewayClient

      public WebsocketGatewayClient(URI endPointUri, WebSocketClient client, io.fluxzero.common.MessageType type, String topic, boolean sendMetrics)
      Constructs a new WebsocketGatewayClient instance using the specified parameters. This constructor initializes the client to connect to a specific WebSocket endpoint for a given message type and topic.
      Parameters:
      endPointUri - the WebSocket base endpoint URI to connect to
      client - the WebSocketClient instance used for configuration
      type - the MessageType defining the category of messages this client handles
      topic - the topic associated with the messages handled by this client if MessageType is MessageType.CUSTOM or MessageType.DOCUMENT or null otherwise
      sendMetrics - a flag indicating whether metrics should be enabled for this client
  • Method Details

    • append

      public CompletableFuture<Void> append(io.fluxzero.common.Guarantee guarantee, io.fluxzero.common.api.SerializedMessage... messages)
      Description copied from interface: GatewayClient
      Append the given messages to the gateway, applying the given delivery Guarantee.
      Specified by:
      append in interface GatewayClient
      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

      public CompletableFuture<Void> setRetentionTime(Duration duration, io.fluxzero.common.Guarantee guarantee)
      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 interface GatewayClient
      Parameters:
      duration - the new retention duration
      guarantee - the delivery guarantee to apply to the update operation
      Returns:
      a CompletableFuture that completes once the retention setting is updated
    • toString

      public String toString()
      Overrides:
      toString in class AbstractWebsocketClient
    • metricsMetadata

      protected io.fluxzero.common.api.Metadata metricsMetadata()
      Overrides:
      metricsMetadata in class AbstractWebsocketClient
    • registerMonitor

      public io.fluxzero.common.Registration registerMonitor(Consumer<List<io.fluxzero.common.api.SerializedMessage>> monitor)