Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

By default, event receivers process incoming messages in the XML, JSON, Text, Map (Key-value pairs), and WSO2Event formatsIf the incoming events adhere to a default format, select the supported default format for Message Format property under Mapping Configuration when creating event receivers.

...

Excerpt

This section covers the following types of input event receiver mappings that WSO2 CEP/DAS supports and how to configure them.

Table of Contents
maxLevel3

WSO2Event input mapping

WSO2Event input mapping allows you to convert events from one WSO2Event format to another. You need to define both the incoming event stream and the mapped event stream for it. A sample mapping configuration is shown below.

The configuration XML file of the above sample mapping is as follows.

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver">
    <from ... />
    <mapping customMapping="enable" type="wso2event">
        <from streamName="sensor.stream" version="1.0.6"/>
        <property>
            <from dataType="meta" name="time"/>
            <to name="meta_timestamp" type="long"/>
        </property>
        <property>
            <from dataType="meta" name="meta_ispowerServed"/>
            <to name="meta_isPowerSaverEnabled" type="bool"/>
        </property>
        <property>
            <from dataType="meta" name="id"/>
            <to name="meta_sensorId" type="int"/>
        </property>
        <property>
            <from dataType="meta" name="name"/>
            <to name="meta_sensorName" type="string"/>
        </property>
        <property>
            <from dataType="correlation" name="correlation_longitude"/>
            <to name="correlation_longitude" type="double"/>
        </property>
        <property>
            <from dataType="correlation" name="correlation_latitude"/>
            <to name="correlation_latitude" type="double"/>
        </property>
        <property>
            <from dataType="payload" name="humid"/>
            <to name="humidity" type="float"/>
        </property>
        <property>
            <from dataType="payload" name="value"/>
            <to name="sensorValue" type="double"/>
        </property>
    </mapping>
    <to ... />
</eventReceiver>

XML input mapping

XML input mapping allows you to convert events of any XML format to the server's canonical event format (WSO2Event) for processing, If the XML message comprises of more then one message, then you can specify a Parent Selector XPath Expression pointing to an XML tag where all it's child elements will be considered as separate XML messages. A sample mapping configuration is shown below.

The configuration XML file of the above sample mapping is as follows.

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver">
    <from ... />
    <mapping customMapping="enable" type="xml">
        <xpathDefinition namespace="http://wso2.org" prefix="sen"/>
        <property>
            <from xpath="//sen:time"/>
            <to name="meta_timestamp" type="long"/>
        </property>
        <property>
            <from xpath="//sen:isPowerSeved"/>
            <to default="true" name="meta_isPowerSaverEnabled" type="bool"/>
        </property>
        <property>
            <from xpath="//sen:id"/>
            <to name="meta_sensorId" type="int"/>
        </property>
        <property>
            <from xpath="//sen:name"/>
            <to name="meta_sensorName" type="string"/>
        </property>
        <property>
            <from xpath="//sen:long"/>
            <to name="correlation_longitude" type="double"/>
        </property>
        <property>
            <from xpath="//sen:lat"/>
            <to name="correlation_latitude" type="double"/>
        </property>
        <property>
            <from xpath="//sen:humidity"/>
            <to name="humidity" type="float"/>
        </property>
        <property>
            <from xpath="//sen:value"/>
            <to name="sensorValue" type="double"/>
        </property>
    </mapping>
    <to ... />
</eventReceiver>                  

JSON input mapping

JSON input mapping allows you to convert events of any JSON format to the server's canonical event format (WSO2Event) for processing. If the JSON message is an array, all the array elements are considered as separate messages when mapping the event. A sample mapping configuration is shown below.

The configuration XML file of the above sample mapping is as follows.

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver">
    <from ... />
    <mapping customMapping="enable" type="json">
        <property>
            <from jsonPath="$.sensorData.time"/>
            <to name="meta_timestamp" type="long"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.powerSaving"/>
            <to default="true" name="meta_isPowerSaverEnabled" type="bool"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.id"/>
            <to name="meta_sensorId" type="int"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.name"/>
            <to default="---" name="meta_sensorName" type="string"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.long"/>
            <to name="correlation_longitude" type="double"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.lat"/>
            <to name="correlation_latitude" type="double"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.humidity"/>
            <to name="humidity" type="float"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.value"/>
            <to name="sensorValue" type="double"/>
        </property>
    </mapping>
    <to ... />
</eventReceiver>                 

Text input mapping

Text input mapping allows you to convert events of any text format to the server's canonical event format (WSO2Event) for processing. Data from the text message are expected to use regular expression patterns. A sample mapping configuration is shown below.

The configuration XML file of the above sample mapping is as follows.

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver">
    <from ... />
    <mapping customMapping="enable" type="text">
        <property>
            <from regex="(\w+)\s(\w+)\s(\w+)\s(\w+)"/>
            <to name="meta_sensorId" type="int"/>
            <to default="--" name="meta_sensorName" type="string"/>
            <to name="correlation_longitude" type="double"/>
            <to name="correlation_latitude" type="double"/>
        </property>
        <property>
            <from regex="time\s(\w+)"/>
            <to name="meta_timestamp" type="long"/>
        </property>
        <property>
            <from regex="powerSaved\s(\w+)"/>
            <to name="meta_isPowerSaverEnabled" type="bool"/>
        </property>
        <property>
            <from regex="value\s(\w+)\s(\w+)"/>
            <to name="humidity" type="float"/>
            <to name="sensorValue" type="double"/>
        </property>
    </mapping>
    <to ... />
</eventReceiver>                

Map input mapping

Map input mapping allows you to convert events of any Map (Key-value pairs) format to the server's canonical event format (WSO2Event) for processing. A sample mapping configuration is shown below.

The configuration XML file of the above sample mapping is as follows.

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver">
    <from ... />
    <mapping customMapping="enable" type="map">
        <property>
            <from name="timestamp"/>
            <to name="meta_timestamp" type="long"/>
        </property>
        <property>
            <from name="isPowerSaverEnabled"/>
            <to name="meta_isPowerSaverEnabled" type="bool"/>
        </property>
        <property>
            <from name="id"/>
            <to name="meta_sensorId" type="int"/>
        </property>
        <property>
            <from name="name"/>
            <to name="meta_sensorName" type="string"/>
        </property>
        <property>
            <from name="long"/>
            <to name="correlation_longitude" type="double"/>
        </property>
        <property>
            <from name="lat"/>
            <to name="correlation_latitude" type="double"/>
        </property>
        <property>
            <from name="humidity"/>
            <to name="humidity" type="float"/>
        </property>
        <property>
            <from name="sensorValue"/>
            <to name="sensorValue" type="double"/>
        </property>
    </mapping>
    <to ... />
</eventReceiver>