Skip to content

Websockets

Overview

Module

Outbound STOMP WebSocket client — connect to a remote endpoint, register a registry-resident handler for lifecycle and message events, then optionally publish or query the platform's view of active connections. Useful for bridging Dirigible into another service that exposes a WebSocket interface (an external trading desk, a chat server, an MQTT bridge).

For inbound WebSockets (handlers exposed by Dirigible to remote clients) use the @Websocket class annotation instead — that gives you onOpen / onMessage / onClose entry points on a Java class.

Key Features:

  • STOMP outbound — connect, return a StompSession for sends and subscriptions.
  • Connection registry — inspect active clients by id, handler name, or as JSON.
  • Inbound counterpart@Websocket annotation for handlers Dirigible serves.

Example Usage:

java
import org.eclipse.dirigible.sdk.net.Websockets;
import org.springframework.messaging.simp.stomp.StompSession;

StompSession session = Websockets.createWebsocket("ws://example.com/stomp", "/my-handler");
session.send("/app/echo", "hello".getBytes());

String activeJson = Websockets.getClientsAsJson();

Methods

createWebsocket()

Opens an outbound STOMP WebSocket connection.

java
public static StompSession createWebsocket(String uri, String handler)
    throws DeploymentException, IOException, InterruptedException, ExecutionException;
ParameterTypeDescription
uriStringTarget WebSocket URL.
handlerStringPath of a registry handler script invoked on lifecycle and message events.

Returns

  • Type: StompSession
  • Description: Live Spring STOMP session — use it to send or subscribe.

getClients()

Returns all active client connections known to the platform.

java
public static List<WebsocketClient> getClients();

Returns

  • Type: List<WebsocketClient>
  • Description: All active WebSocket clients.

getClientsAsJson()

Same as getClients() but serialised to JSON for easy forwarding.

java
public static String getClientsAsJson();

getClient()

Finds a client by id.

java
public static WebsocketClient getClient(String id);
ParameterTypeDescription
idStringClient id.

Returns

  • Type: WebsocketClient
  • Description: The matching client, or null. |

getClientByHandler()

Finds a client by its registered handler path.

java
public static WebsocketClient getClientByHandler(String handler);
ParameterTypeDescription
handlerStringHandler path.

Returns

  • Type: WebsocketClient
  • Description: The matching client, or null. |

Released under the EPL-2.0 License.