如何在 mule 中创建一个 websocket 客户端
how to create a websocket client in mule
我正在尝试在连接到外部服务器 websocket 的 mule 中创建一个 websocket 客户端。我还想在连接请求时将 headers 和 body 发送到外部 websocket。如何在骡子中实现这一目标?
如何发送 WebSockets 请求和设置 headers 在 Mule WebSockets connector documentation. To send information you can use the send operation 中有说明。
示例
<websocket:config name="wsClient">
<websocket:connection>
<websocket:client-settings host="localhost" port="${listenerPort}" basePath="/ws">
<websocket:default-headers>
<websocket:header key="myFirstDefaultHeader" value="defaultHeader1" />
<websocket:header key="mySecondDefaultHeader" value="defaultHeader2" />
</websocket:default-headers>
<websocket:default-query-params>
<websocket:query-param key="myFirstDefaultQueryParam" value="query1" />
<websocket:query-param key="mySecondDefaultQueryParam" value="query2" />
</websocket:default-query-params>
</websocket:client-settings>
</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!"/>
<websocket:send socketId="myCustomWebSocketID-123" config-ref="wsClient">
<websocket:content>'Hello world!'</websocket:content>
</websocket:send>
</flow>
我正在尝试在连接到外部服务器 websocket 的 mule 中创建一个 websocket 客户端。我还想在连接请求时将 headers 和 body 发送到外部 websocket。如何在骡子中实现这一目标?
如何发送 WebSockets 请求和设置 headers 在 Mule WebSockets connector documentation. To send information you can use the send operation 中有说明。
示例
<websocket:config name="wsClient">
<websocket:connection>
<websocket:client-settings host="localhost" port="${listenerPort}" basePath="/ws">
<websocket:default-headers>
<websocket:header key="myFirstDefaultHeader" value="defaultHeader1" />
<websocket:header key="mySecondDefaultHeader" value="defaultHeader2" />
</websocket:default-headers>
<websocket:default-query-params>
<websocket:query-param key="myFirstDefaultQueryParam" value="query1" />
<websocket:query-param key="mySecondDefaultQueryParam" value="query2" />
</websocket:default-query-params>
</websocket:client-settings>
</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!"/>
<websocket:send socketId="myCustomWebSocketID-123" config-ref="wsClient">
<websocket:content>'Hello world!'</websocket:content>
</websocket:send>
</flow>