Class WebsocketGatewayClient
- All Implemented Interfaces:
Monitored<List<SerializedMessage>>
,GatewayClient
,AutoCloseable
GatewayClient
implementation that sends serialized messages to the Flux Platform over a WebSocket
connection.
This client is used internally by the Flux Capacitor framework to publish messages (commands, events, queries, etc.)
to the platform backend 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
FluxCapacitor
.
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 io.fluxcapacitor.javaclient.common.websocket.AbstractWebsocketClient
AbstractWebsocketClient.PingRegistration, AbstractWebsocketClient.WebSocketRequest
-
Field Summary
Fields inherited from class io.fluxcapacitor.javaclient.common.websocket.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 Metadata
registerMonitor
(Consumer<List<SerializedMessage>> monitor) Registers a monitor that will be notified when an activity of typeT
occurs.setRetentionTime
(Duration duration, Guarantee guarantee) Set a new retention duration for the underlying gateway's message log.toString()
Methods inherited from class io.fluxcapacitor.javaclient.common.websocket.AbstractWebsocketClient
abort, close, close, handleResult, onClose, onError, onMessage, onOpen, onPong, retryOutstandingRequests, schedulePing, send, sendAndWait, sendCommand, sendPing, tryPublishMetrics
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.publishing.client.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
messageType
isMessageType.METRICS
.- Parameters:
endPointUrl
- the WebSocket base endpoint URI to connect toclient
- the WebSocketClient instance used for configurationtype
- theMessageType
defining the category of messages this client handlestopic
- the topic associated with the messages handled by this client ifMessageType
isMessageType.CUSTOM
orMessageType.DOCUMENT
ornull
otherwise
-
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
- theMessageType
defining the category of messages this client handlestopic
- the topic associated with the messages handled by this client ifMessageType
isMessageType.CUSTOM
orMessageType.DOCUMENT
ornull
otherwisesendMetrics
- a flag indicating whether metrics should be enabled for this client
-
-
Method Details
-
append
Description copied from interface:GatewayClient
Append the given messages to the gateway, applying the given deliveryGuarantee
.- Specified by:
append
in 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
CompletableFuture
that completes when the append operation is successful or fails if delivery fails
-
setRetentionTime
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 interfaceGatewayClient
- Parameters:
duration
- the new retention durationguarantee
- the delivery guarantee to apply to the update operation- Returns:
- a
CompletableFuture
that completes once the retention setting is updated
-
toString
- Overrides:
toString
in classAbstractWebsocketClient
-
metricsMetadata
- Overrides:
metricsMetadata
in classAbstractWebsocketClient
-
registerMonitor
Description copied from interface:Monitored
Registers a monitor that will be notified when an activity of typeT
occurs.- Specified by:
registerMonitor
in interfaceMonitored<List<SerializedMessage>>
- Parameters:
monitor
- the callback to invoke with each observed value- Returns:
- a
Registration
that can be used to cancel the monitoring
-