Class WebsocketGatewayClient
- All Implemented Interfaces:
Monitored<List<SerializedMessage>>, GatewayClient, AutoCloseable
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:
-
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
ConstructorsConstructorDescriptionWebsocketGatewayClient(String endPointUrl, WebSocketClient client, MessageType type, String topic) Constructs a new WebsocketGatewayClient instance using the specified parameters.WebsocketGatewayClient(URI endPointUri, WebSocketClient client, MessageType type, String topic, boolean sendMetrics) Constructs a new WebsocketGatewayClient instance using the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionappend(Guarantee guarantee, SerializedMessage... messages) Append the given messages to the gateway, applying the given deliveryGuarantee.protected MetadataregisterMonitor(Consumer<List<SerializedMessage>> monitor) Registers a monitor that will be notified when an activity of typeToccurs.setRetentionTime(Duration duration, Guarantee guarantee) Set a new retention duration for the underlying gateway's message log.toString()Methods inherited from class AbstractWebsocketClient
abort, close, close, handleResult, onClose, onError, onMessage, onOpen, onPong, retryOutstandingRequests, schedulePing, send, sendAndWait, sendCommand, sendPing, tryPublishMetricsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface GatewayClient
close
-
Constructor Details
-
WebsocketGatewayClient
public WebsocketGatewayClient(String endPointUrl, WebSocketClient client, 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
messageTypeisMessageType.METRICS.- Parameters:
endPointUrl- the WebSocket base endpoint URI to connect toclient- the WebSocketClient instance used for configurationtype- theMessageTypedefining the category of messages this client handlestopic- the topic associated with the messages handled by this client ifMessageTypeisMessageType.CUSTOMorMessageType.DOCUMENTornullotherwise
-
WebsocketGatewayClient
public WebsocketGatewayClient(URI endPointUri, WebSocketClient client, 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 toclient- the WebSocketClient instance used for configurationtype- theMessageTypedefining the category of messages this client handlestopic- the topic associated with the messages handled by this client ifMessageTypeisMessageType.CUSTOMorMessageType.DOCUMENTornullotherwisesendMetrics- a flag indicating whether metrics should be enabled for this client
-
-
Method Details
-
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
-
toString
- Overrides:
toStringin classAbstractWebsocketClient
-
metricsMetadata
- Overrides:
metricsMetadatain classAbstractWebsocketClient
-
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
-