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.
The following should be completed before running the sample.
- Set up the prerequisites required for all samples.
Navigate to the
<DAS_HOME>/samples/cep/utils/input-websocket-local-adapterdirectory and execute the following command.
This copies the
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 II: On the browser console, type:
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.
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.