If your application needs to connect to external WebSockets services, provide the client settings element:
<websocket:config name="wsClient">
<websocket:connection>
<websocket:client-settings
host="localhost"
port="80"
basePath="/ws" />
</websocket:connection>
</websocket:config>
<flow="connectToWebSocketFlow">
<websocket:open-outbound-socket
path="/chat"
socketId="myCustomWebSocketID-123"
config-ref="wsClient" />
</websocket:open-outbound-socket>
<logger info="INFO" message="Opened connection to external service!"/>
</flow>
In this example we have initialized an outbound socket which references the WebSockets client configuration ("wsClient") in the config-ref attribute. In this case, there is no need to reference an HTTP configuration.
In the configuration above, a host, port, and basePath are specified to build the WS request URI. The host parameter is optional; if not set it is set to localhost.
The port parameter is optional; if not specified the default value is set according to the protocol scheme. If WS is used, the default value is set to 80. If WSS is used, the default is set to 443.
The basePath parameter is optional; if the URI is not set, it indicates the base path for all client requests relative to the indicated host and port. If the basePath parameter is not set, the default value is set to /.
You can also specify a URL:
<websocket:config name="wsClient">
<websocket:connection>
<websocket:client-settings uri="ws://www.mulesoft.com" />
</websocket:connection>
</websocket:config>
However, in this case a path cannot be indicated because the URL and path parameters are mutually exclusive. This is because URL indicates a full resource locator, while the path indicates a path relative to the host, port, and basePath.