Websockets
Overview
Module
- package:
org.eclipse.dirigible.sdk.net - source: net/Websockets.java
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
StompSessionfor sends and subscriptions. - Connection registry — inspect active clients by id, handler name, or as JSON.
- Inbound counterpart —
@Websocketannotation for handlers Dirigible serves.
Example Usage:
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.
javapublic static StompSession createWebsocket(String uri, String handler) throws DeploymentException, IOException, InterruptedException, ExecutionException;
Parameter Type Description 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.
javapublic static List<WebsocketClient> getClients();Returns
- Type:
List<WebsocketClient>- Description: All active WebSocket clients.
getClientsAsJson()
Same as getClients() but serialised to JSON for easy forwarding.
javapublic static String getClientsAsJson();
getClient()
Finds a client by id.
javapublic static WebsocketClient getClient(String id);
Parameter Type Description idStringClient id. Returns
- Type:
WebsocketClient- Description: The matching client, or
null. |
getClientByHandler()
Finds a client by its registered handler path.
javapublic static WebsocketClient getClientByHandler(String handler);
Parameter Type Description handlerStringHandler path. Returns
- Type:
WebsocketClient- Description: The matching client, or
null. |