This documentation is for WSO2 Enterprise Service Bus version 5.0.0. For the latest ESB, view the latest WSO2 Enterprise Integrator documentation.

All docs This doc
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
||
Skip to end of metadata
Go to start of metadata

The following sections walk you through a sample scenario that demonstrates how to send a message from a WebSocket client to an HTTP endpoint via WSO2 ESB:

Introduction

If you need to send a message from a WebSocket client to an HTTP endpoint via WSO2 ESB, you need to establish a persistent Websocket connection from the WebSocket client to WSO2 ESB.
To demonstrate this scenario, you need to create two dispatching sequences. One for the client to back-end mediation, and another for the back-end to client mediation. Finally you need to configure WSO2 ESB's WebSocket inbound endpoint to use the created sequences and listen on port 9091.

Prerequisites

Configuring the sample scenario

  • Create the sequence for client to back-end mediation as follows:

    <sequence name="dispatchSeq">
      <switch source="get-property('websocket.source.handshake.present')">
        <case regex="true">
          <drop/>
        </case>
        <default>
          <call>
            <endpoint>
             <address uri="http://www.mocky.io/v2/56f84ee5240000d1127866c8"/>
            </endpoint>
          </call>
         <respond/>
         </default>
       </switch>
    </sequence>

    This sequence calls an HTTP endpoint.

  • Create the sequence for back-end to client mediation as follows:

    <sequence name="outDispatchSeq" xmlns="http://ws.apache.org/ns/synapse">
      <log/>
      <respond/>
    </sequence>
  • Configure WSO2 ESB's WebSocket inbound endpoint as follows to use the created sequences and listen on port 9091:

    <inboundEndpoint name="test" onError="falut" protocol="ws"
       	sequence="dispatchSeq" suspend="false">
       	<parameters>
           	<parameter name="inbound.ws.port">9091</parameter>
           	<parameter name="ws.outflow.dispatch.sequence">outDispatchSeq</parameter>
           	<parameter name="ws.client.side.broadcast.level">0</parameter>
           	<parameter name="ws.outflow.dispatch.fault.sequence">fault</parameter>
       	</parameters>
    </inboundEndpoint>
    

Executing the sample scenario

  • Execute the following command to start the WebSocket client:

    java -DclientPort=9091 -cp netty-example-4.0.30.Final.jar:lib/*:. io.netty.example.http.websocketx.client.WebSocketClient

Analyzing the output

If you analyze the log, you will see that a connection from the WebSocket client to WSO2 ESB is established. You will also see that the sequences are executed by the WebSocket inbound endpoint.



  • No labels