WSO2 Event — A Brief Introduction
What is Transport?
A transport is responsible for carrying messages that are in a specific format. There are many transport modes such as TCP, Kafka, WSO2 Event, HTTP and etc. In this blog we are particularly going to discuss about wso2 event and how does it work
What is WSO2 Event and how does it publish events from publishers?
WSO2 Event is one of the trendy transport mode that publishes events using thrift as a protocol. In WSO2 Event we have two collections to store events. One is queue. Other one is Batch. We can configure batch size and queue size in the configuration file. Client sends the events to queue. Then from the queue, Batch randomly picks events and sends those events to the server at once.
Let’s try to understand the procedure with a simple example shown in the above diagram.
According to Figure 1 client sends more than eight events to the queue. But Batch size is configured as five. So at once it can take maximum five events from the queue to server. Please note if client sends only three events to the queue, then batch takes only three events at once from queue. It won’t wait until five events fills in the queue. So batch size means the maximum number events that can be sent from client to server at once.
The combination of queue and batch is called as Data Bridge.
Data Bridge = Queue + Batch
So Data Bridge is the pipeline where events travel from client to server.
This is a brief explanation how does wso2 event publish events.
Quick Start with WSO2 Event
Step : 1
Install Oracle Java SE Development Kit (JDK) version 1.8* and set the JAVA_HOME
environment variable.
Step : 2
Download the WSO2 Stream Processor. You can find the latest SP here.
Step : 3
Extract the zip folder and navigate to the <SP_HOME>/bin directory and issue the following command to start the WSO2 SP Editor.
For Windows : editor.batFor Linux : sh editor.sh
After you are successfully start the Stream processor, your Linux terminal should look like this.
Step : 4
Now you can access Stream processor editor via following url (the default url).
http://localhost:9090/editor
Step : 5
Click New to start defining a new execution plan. A new file opens as shown below.
Step : 6
Now we are going to write siddhi app in the editor.
Okay, now let’s dive deep into the siddhi app
- @source(type=’wso2event’,
A contract that consumes data from external sources (such as WSO2 Event , TCP )in the form of events, then converts each event (which can be in XML
, JSON
, binary
, etc. format) to a Siddhi event, and passes that to a Stream for processing.
- @map(type=’wso2event’))
Each @source
configuration has a mapping denoted by the @map
annotation that converts the incoming messages format to Siddhi events. The type
parameter of the @map
defines the map type to be used to map the data.
The following is a list of currently supported source mapping types:
- WSO2Event
- XML
- TEXT
- JSON
- Binary
- Key Value
- @sink(type=’wso2event’
A contract that takes events arriving at a stream, maps them to a predefined data format (such as XML
, JSON
, binary
, etc), and publishes them to external endpoints (such as E-mail
, TCP
, Kafka
, HTTP
, wso2 event etc).
Step: 7
To save the siddhi app click ‘File’ and then click ‘Save as’.
Enter the file name with siddhi extension and <SP Home>/wso2/worker/deployment/siddhi-files in the location filed and click save button. This ensure that the siddhi app you created is deployed when a worker node started.
Step : 8
Start worker node by issuing following command from the <SP-HOME>/bin
For Windows : worker.bat
For Linux : worker.sh
Step : 9
Open a new terminal from <SP-HOME>/samples/sample-clients/wso2event-client directory and issue following command.
ant -Dport=7611 -Dhost=localhost
Please note rather than using worker node you can also use stream processor studio to simulate events. It has in- built support to simulate events.
You have successfully published events using WSO2 Event :)