WebSockets メッセージング操作 - Mule 4

Send 操作

Send 操作により、接続が確立された後にそのソケット ID によって識別される WebSocket を通じてメッセージを送信できます。この操作は、インバウンドとアウトバウンドの両方の WebSocket インスタンスで使用できます。

    <flow name="sayHello">
      <websocket:open-outbound-socket
        path="/chat/hello"
        config-ref="ws"
        target="socketId"
        targetValue="#[attributes.socketId]"/>
      <websocket:send socketId="#[vars.socketId]" config-ref="ws">
        <websocket:content>'Good morning!'</websocket:content>
      </websocket:send>
    </flow>

    <flow name="sayHelloBack">
        <websocket:inbound-listener
            path="/chat/hello"
            config-ref="ws"
            outputMimeType="text/plain" />
        <websocket:send socketId="#[attributes.socketId]" config-ref="ws">
            <websocket:content>#['Good morning ' ++ attributes.socketId ++ '!']</websocket:content>
        </websocket:send>
    </flow>
xml

Broadcast 操作

Broadcast 操作はメッセージをソケットのグループに送信します。メッセージをブロードキャストできるソケットのグループを選択する手順は、次のとおりです。

  • 特定のグループをサブスクライブする

  • 特定のパスに接続する

  • 特定の種別にする (INBOUND または OUTBOUND)

種別およびグループパラメーターは連携して加法的に機能します。省略することも個別に使用することもできますが、一緒に使用すると 2 つのレベルの絞り込みとして動作します。

<!-- Send to all INBOUND sockets connected to the /quotes endpoint, in the MARVEL and DC groups -->
<websocket:broadcast
    doc:name="Broadcast"
    socketType="INBOUND"
    config-ref="WebSockets_Config"
    path="/quotes">
    <websocket:groups >
        <websocket:group value=" #[['MARVEL', 'DC']]" />
    </websocket:groups>
</websocket:broadcast>
xml

出力

Broadcast 操作の出力は void です。