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 a WebSocket endpoint via WSO2 ESB:

Introduction

If you need to send a message from a WebSocket client to a WebSocket endpoint via WSO2 ESB, you need to establish a persistent Websocket connection from the WebSocket client to WSO2 ESB as well as from WSO2 ESB to the WebSocket back-end.

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">
         <property name="OUT_ONLY" value="true"/>
         <send>
             <endpoint>
                 <address uri="ws://localhost:8082/websocket"/>
             </endpoint>
         </send>
    </sequence>
  • Create the sequence for back-end to client mediation as follows:

    <sequence name="outDispatchSeq" xmlns="http://ws.apache.org/ns/synapse">
       <log level="full"/>
       <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="fault" 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, and the sequences are executed by the WebSocket inbound endpoint.

You will also see that the message sent to the WebSocket server is not transformed, and that the response injected to the out sequence is also not transformed.

  • No labels