This documentation is for WSO2 Complex Event Processor 4.0.0. View documentation for the latest release.
WSO2 Complex Event Processor is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.
||
Skip to end of metadata
Go to start of metadata

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.

However, if the incoming events do not adhere to a default format, when creating event receivers select the supported format for Message Format, click the Advanced section, and provide input mappings to convert the message to a canonical format for the server to understand the message and process it.

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

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.

<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>

Events with null or empty attributes

In case of an event is received with null or empty attributes the behaviour for WSO2Event Input mapping is as follows.

  • Non-String Attributes (e.g. int, double, long etc.)
    • null - CEP will throw an error and the event will be dropped

    • Empty Attribute - Error will be thrown and event will be dropped
  • String Attributes
    • null - It will be processed as a null value
    • Empty Attribute - It will be processed as an empty string

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.

<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>                  

Events with null or empty attributes

In case of an event is received with null or empty attributes the behaviour for XML Input mapping is as follows.

  • Non-String Attributes (e.g. int, double, long etc.)
    • null - CEP will throw an error and the event will be dropped

    • Empty Attribute - Error will be thrown and event will be dropped
  • String Attributes
    • null - It will be processed as a null value
    • Empty Attribute - It will be processed as an empty string

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.

<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>                 

Events with null or empty attributes

In case of an event is received with null or empty attributes the behaviour for JSON Input mapping is as follows.

  • Non-String Attributes (e.g. int, double, long etc.)
    • null - CEP will throw an error and the event will be dropped

    • Empty Attribute - Error will be thrown and event will be dropped
  • String Attributes
    • null - It will be processed as a null value
    • Empty Attribute - It will be processed as an empty string

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.

<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>                

Events with null or empty attributes

In case of an event is received with null or empty attributes the behaviour for Text Input mapping is as follows.

  • Non-String Attributes (e.g. int, double, long etc.)
    • null - CEP will throw an error and the event will be dropped

    • Empty Attribute - Error will be thrown and event will be dropped
  • String Attributes
    • null - It will be processed as a null value
    • Empty Attribute - It will be processed as an empty string

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.

<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>                  

Events with null or empty attributes

In case of an event is received with null or empty attributes the behaviour for Map Input mapping is as follows.

  • Non-String Attributes (e.g. int, double, long etc.)
    • null - CEP will throw an error and the event will be dropped

    • Empty Attribute - Error will be thrown and event will be dropped
  • String Attributes
    • null - It will be processed as a null value
    • Empty Attribute - It will be processed as an empty string
  • No labels