Contact Free trial Login

WebSockets Connection Close - Mule 4

This operation closes currently connected WebSockets referenced by a Socket ID.

<flow name="closeConnection">
    <websocket:close-socket
        socketId="#[attributes.socketId]"
        reason="Quota exceeded"/>
</flow>

Close Output

This operation returns no payload or attributes.

On Socket Closed

A message source triggers a flow each time a WebSocket is closed. This is useful to perform cleanup operations, logging, or updating the app’s state.

This is asynchronous. By the time the flow is invoked the socket has already been closed. Trying to send messages through the referenced WebSocket results in an error.

<flow name="onConnectionClosed">
    <websocket:on-connection-closed path="/chat/*" config-ref="ws" />
    <logger
        level="INFO"
        message="No more messages please: you shall not pass." />
</flow>

<flow name="receiveMessagesFlow">
    <websocket:on-inbound-connection path="/chat" config-ref="ws" />
    <logger
        level="INFO"
        message="Someone just sent a message and now I will close this connection!" />

    <websocket:close-socket
        socketId="#[attributes.socketId]"
        reason="I don't like to talk."
        config-ref="ws" />
</flow>

The path parameter indicates the path of sockets that when closed, trigger the flow. To indicate catch-all, you can use the asterisk wildcard symbol (∗).

On Socket Closed Output

This operation returns an empty payload and a WebSocketAttributes object in the attributes.