This sample demonstrates how the WSO2 CEP can receive (and then process if required) events from a Websocket client.
Refer to below image to get an overview of the event flow.
Refer to the below steps, which we are going to do in this sample:
- Step 1: Start CEP server. This will start a Websocket server which is in-built to CEP.
- Step 2: Define an Event Stream in CEP.
- Step 3: Create an Input Websocket-local Event Adapter, so CEP can receive events of type defined in step 1.
- Step 4: Create an Output Logger Event Adapter, so whenever CEP receives an event, it will be logged on the console on which CEP server runs.
- Step 5: Now we can connect to the CEP-websocket server and publish events to it, using a Websocket client. As we publish messages, those messages will be logged in the CEP console.
Note that, for simplicity, we do not set up CEP to process the events received by the Websocket-local Input Adapter. Instead of processing events using execution plans, those will be directly handed over to the Output Logger Adapter for logging. This is indicated in the above diagram by making the 'Event Processor' component almost transparent: to show that it does not do any processing.
Set up the prerequisites required for all samples.
In addition to that, go to
<CEP_HOME>/samples/cep/utils/input-websocket-local-adapter directory and execute the following command:
This will copy inputwebsocket.war webapp to
Starting sample CEP configurations
Start the WSO2 CEP server with the sample configuration numbered 0020. For instructions, see Starting sample CEP configurations.
This sample configuration points the default Axis2 repo to
<CEP_HOME>/sample/cep/artifacts/0020 (by default, the Axis2 repo is
<CEP_HOME>/repository/deployment/server). As a result, the artifacts in the
<CEP_HOME>/sample/cep/artifacts/0020 directory are deployed.
When these sample configurations are deployed:
- An event stream will be defined.
- An Input Websocket-local Event Adapter will be created.
- An Output Logger Event Adapter will be created.
In other words, all the first four steps listed in Introduction section will be done, when the server is started with sample configuration number 0020.
Now the remaining task is connect to the CEP-websocket server and publish events to it.
Connect to CEP via a Websocket client
In this sample, you will use your web browser 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 CEP 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 we're ready to publish events to the CEP.
Step III: Next and final step is to publish three events to the CEP. Following are the three events which we will publish to CEP:
To publish the above three events to the CEP, we will use the following three commands, each of which will publish an event to CEP.
Copy and paste each command on the browser console and press enter.
This is shown in the screenshot below:
As you publish events to the CEP using the web browser client, check the CEP console. It will print the logs, indicating that it received the events sent by the browser. This is shown in the screenshot below: