This sample demonstrates how the WSO2 DAS can publish events to a Websocket client.
Refer to below image to get an overview of the event flow.
The following is a summary of the steps that are followed to run this sample.
- Step 1: Start the DAS server. This starts an inbuilt Websocket server in DAS.
- Step 2: Define an Event Stream in DAS.
- Step 3: Create an Output Websocket-local Event Adapter so that events of the type defined in step 1 are published via the DAS Websocket server.
- Step 4: Connect a Websocket client to the Websocket Server in DAS.
- Step 5: Send a few events to the DAS. The inbuilt Event Simulator tool in DAS is used for this purpose. The events sent are received by the Websocket client.
See Prerequisites in the CEP Samples Setup page.
In addition to that, go to
<DAS_HOME>/samples/cep/utils/output-websocket-local-adapter directory and execute the following command:
This copies the
outputwebsocket.war webapp to
Starting sample CEP configurations
Start the WSO2 DAS server with the sample configuration numbered
0070 For instructions, see Starting sample CEP configurations.
This sample configuration points the default Axis2 repo to
<DAS_HOME>/samples/cep/artifacts/0070 (by default, the Axis2 repo is
<DAS_HOME>/repository/deployment/server). As a result, the artifacts in
<DAS_HOME>/sample/artifacts/0070 directory are deployed.
When these sample configurations are deployed:
- An event stream is defined.
- The event simulator is available to play a set of events to DAS.
- An Output Websocket-local Event Adapter will be created.
In other words, all the first three steps listed in Introduction section are completed when the server is started with sample configuration number
Now the remaining tasks are to execute steps 4 and 5: connect a Websocket client, and send a few events to the CEP.
Connect to DAS via a Websocket client (to receive events)
In this sample, you will use your web browser as the Websocket client. However, any Websocket client can be used for this purpose.
Note: If you have started DAS server on a different host and a port, replace
localhost in the above command with that host, and
9763 with that port, respectively. See Running the Product page for more details.
This step is shown in the screenshot below.
Upon successful connection, you will see an output in the same console as shown in the below screenshot.
Now this browser-client is ready to receive events from the DAS.
Step III: Next and final step is to send four events to the DAS. We will send the following four events of type
org.wso2.event.sensor.stream to the DAS.
The Event Simulator tool in DAS is used to send events.
To use the Event Simulator, log in to the DAS Management Console and go to Tools --> Event Simulator.
In the Event Simulator page, an input data file ready to be played is displayed in the Send Multiple Events section. Click Play as shown in the screenshot below to send the events included in this data file to the DAS.
As the events are being played, you will see four alerts from your browser, indicating the receipt of events. One such alert is shown in the image below.