Sample 0120 - Using the Map Extension
Introduction
This sample demonstrates the usage of the map extension with a basic pass through query. It selects some attributes that are specific for the each incoming event and gives an output event with the selected attributes. This receives data via an http request. The received events are logged by the log event publisher.
The following three queries are performed in the given order.
The following query is performed on the received data from theÂ
DataIn
event stream. Then specific objects are filtered from the received stream and published to theÂinnerStream
.from dataIn select name,map:createFromJSON(specificAttributesObj) as specAttrObjMap insert into innerStream;
The following query retrieves data from theÂ
innerStream
. Then the temperature value that belongs to the specific attributes are sent toÂinnerStreamTwo
with the name of the event.from innerStream select name,map:get(specAttrObjMap,'temperature') as temp insert into innerStreamTwo;
If the temperature value is not
null
in the stream received fromÂinnerStreamTwo
, the following query casts the temperature value into a string and publishes it to theÂdataOut
stream with the event name.from innerStreamTwo[not(temp is null)] select name, cast(temp, 'string') as temperature insert into dataOut;
Prerequisites
Set up the prerequisites required for all samples.
Building the sample
Start the WSO2 DAS server with the sample configuration numbered 0120. For instructions, see Starting sample CEP configurations.
This sample configuration points the default Axis2 repo to <DAS_HOME>/samples/cep/artifacts/0120
 (by default, the Axis2 repo is <DAS_HOME>/repository/deployment/server
).
Executing the sample
Open a new tab in your CLI and execute the following ant command from the <DAS_HOME>/samples/cep/producers/http
directory.
ant -Durl=http://localhost:9763/endpoints/httpReceiver -Dsn=0120
The other optional parameters that can be used in the above command are defined in the <DAS_HOME>/samples/cep/producers/http/build.xml
file.
This builds the HTTP client and publishes the events in the <DAS_HOME>/samples/cep/artifacts/0120/httpReceiver.txt
file to the httpReceiver
endpoint. You can view the details of the events that are sent as shown in the log below.
JSON events are logged as shown below.
Â