WSO2 Data Analytics Server is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.

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

Introduction

This sample demonstrates how the WSO2 DAS can receive events from a Websocket client and then process them if required.

The following diagram provides an overview of the event flow.

The following is a summary of the steps followed in this sample

  • Step 1: Start the DAS server. This starts an in-built Websocket server in DAS.
  • Step 2: Define an Event Stream in DAS.
  • Step 3: Create an Input Websocket-local Event Adapter in order to allow WSO2 DAS to receive events of the type defined in step 1.
  • Step 4: Create an Output Logger Event Adapter to ensure that events received by WSO2 DAS are logged in the console on which the WSO2 DAS server is run.
  • Step 5: Connect to the DAS-websocket server and publish events to it, using a Websocket client. The published messages are logged in the DAS console.

Note that, for simplicity, we do not set up WSO2 DAS to process the events received by the Websocket-local Input Adapter. Instead of processing events using execution plans, the events are directly sent over to the Output Logger Adapter for logging. This is indicated in the above diagram where the Event Processor component almost transparent to show that it does not do any processing.

Prerequisites

The following should be completed before running the sample.

  1. Set up the prerequisites required for all samples.
  2. Navigate to the <DAS_HOME>/samples/cep/utils/input-websocket-local-adapter directory and execute the following command.

    ant -Dsn=0020

    This copies the inputwebsocket.war webapp to <DAS_HOME>/sample/cep/artifacts/0020/webapps directory. 

Starting sample CEP configurations 

Start the WSO2 DAS server with the sample configuration numbered 0020. For instructions, see Starting sample CEP configurations.

This sample configuration points the default Axis2 repo to <DAS_HOME>/sample/cep/artifacts/0020 (by default, the Axis2 repo is <DAS_HOME>/repository/deployment/server). As a result, the artifacts in the <DAS_HOME>/sample/cep/artifacts/0020 directory are deployed.

When these sample configurations are deployed:

  • An event stream is defined.
  • An Input Websocket-local Event Adapter is created.
  • An Output Logger Event Adapter is created.

In other words, all the first four steps listed in Introduction section are completed once the server is started with the sample configuration number 0020.

The remaining task is to connect to the DAS-websocket server and publish events to it.

Connect to DAS via a Websocket client

In this sample, the web browser is used as the Websocket client. However, any Websocket client can be used for this purpose.

Step I: Start a web browser and go to its Javascript console. In most browsers, such as Chrome and Firefox, you can load the Javascript console by simply pressing the keys Ctrl+Shift+J (or Cmd+Option+J on a Mac). 

Ensure that the page on which you open the Javascript Console is loaded over HTTP. For example, you can open the page http://wso2.com and load the Javascript console on that page.

Step II: On the browser console, type:

var ws = new WebSocket("ws://localhost:9763/inputwebsocket/wsLocalInputAdapter");

Note: If you have started the 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, the output is displayed in the same console as shown below.

Now we're ready to publish events to WSO2 DAS.

Step III: Next and final step is to publish three events to WSO2 DAS. The following are the three events o be published.

Issue the following three commands. Each command publishes an event to WSO2 DAS.

ws.send("{\"event\": {\"metaData\":{\"timestamp\": 4354643,\"isPowerSaverEnabled\": false,\"sensorId\": 701,\"sensorName\": temperature},\"correlationData\": {\"longitude\": 4.504343,\"latitude\": 20.44345},\"payloadData\": {\"humidity\": 2.3,\"sensorValue\": 4.504343}}}");
ws.send("{\"event\": {\"metaData\": {\"timestamp\": 4354643,\"isPowerSaverEnabled\": false,\"sensorId\": 702,\"sensorName\": temperature},\"correlationData\": {\"longitude\": 4.504343,\"latitude\": 20.44345},\"payloadData\": {\"humidity\": 2.3,\"sensorValue\": 4.504343}}}");
ws.send("{\"event\": {\"metaData\": {\"timestamp\": 4354643,\"isPowerSaverEnabled\": false,\"sensorId\": 703,\"sensorName\": temperature},\"correlationData\": {\"longitude\": 4.504343,\"latitude\": 20.44345},\"payloadData\": {\"humidity\": 2.3,\"sensorValue\": 4.504343}}}");

This is shown in the screenshot below:

Events sent by the browser and received by DAS are logged in the DAS console as shown below.


  • No labels