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 /wiki/spaces/TESB/pages/32604416, 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.

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.

Image Removed

The configuration XML file of the above sample
Info
titleEvents 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.

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"/>
  • 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
Anchor
XMLInputMapping
XMLInputMapping

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.

Image Added

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  </property>namespace="http://wso2.org" prefix="sen"/>
        <property>
            <from xpath="//sen:isPowerSevedtime"/>
            <to default="true" name="meta_isPowerSaverEnabledtimestamp" type="boollong"/>
        </property>
        <property>
            <from xpath="//sen:idisPowerSeved"/>
            <to default="true" name="meta_sensorIdisPowerSaverEnabled" type="intbool"/>
        </property>
        <property>
            <from xpath="//sen:nameid"/>
            <to name="meta_sensorNamesensorId" type="stringint"/>
        </property>
        <property>
            <from xpath="//sen:longname"/>
            <to name="correlationmeta_longitudesensorName" type="doublestring"/>
        </property>
        <property>
            <from xpath="//sen:latlong"/>
            <to name="correlation_latitudelongitude" type="double"/>
        </property>
        <property>
            <from xpath="//sen:humiditylat"/>
            <to name="humiditycorrelation_latitude" type="floatdouble"/>
        </property>
        <property>
            <from xpath="//sen:valuehumidity"/>
            <to name="sensorValuehumidity" type="doublefloat"/>
        </property>
     </mapping>   <property>
     <to ... /> </eventReceiver>    <from xpath="//sen:value"/>
            

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.

Image Removed

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

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver"><to name="sensorValue" type="double"/>
        </property>
    </mapping>
    <to ... />
</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"    
Info
titleEvents 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
Anchor
JSONInputMapping
JSONInputMapping

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.

Image Added

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

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver">
    <from ... />
        </property><mapping customMapping="enable" type="json">
        <property>
            <from jsonPath="$.sensorData.nametime"/>
            <to default="---" name="meta_sensorNametimestamp" type="stringlong"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.longpowerSaving"/>
            <to default="true" name="correlationmeta_longitudeisPowerSaverEnabled" type="doublebool"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.latid"/>
            <to name="correlationmeta_latitudesensorId" type="doubleint"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.humidityname"/>
            <to default="---" name="humiditymeta_sensorName" type="floatstring"/>
        </property>
        <property>
            <from jsonPath="$.sensorData.valuelong"/>
            <to name="sensorValuecorrelation_longitude" type="double"/>
        </property>
    </mapping>    <property>
            <to<from jsonPath="$.sensorData.. lat"/>
</eventReceiver>            <to name="correlation_latitude" type="double"/>
        </property>
       

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.

Image Removed

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

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver"> <property>
            <from jsonPath="$.sensorData.humidity"/>
     <from ... />     <mapping<to customMappingname="enablehumidity" type="textfloat"/>
        </property>
        <property>
            <from regex="(\w+)\s(\w+)\s(\w+)\s(\w+)jsonPath="$.sensorData.value"/>
            <to name="meta_sensorIdsensorValue" type="intdouble"/>
        </property>
    <to default="--" name="meta_sensorName" type="string"/>
            <to name="correlation_longitude" type="double"/>
  </mapping>
    <to ... />
</eventReceiver>          <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>
Info
titleEvents 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.

Image Added

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="value(\w+)\s(\w+)\s(\w+)\s(\w+)"/>
            <to name="humiditymeta_sensorId" type="floatint"/>
            <to default="--" name="sensorValuemeta_sensorName" type="doublestring"/>
        </property>     </mapping><to name="correlation_longitude" type="double"/>
            <to ... />
</eventReceiver>name="correlation_latitude" type="double"/>
        </property>
        <property>
            

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.

Image Removed

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

Code Block
languagehtml/xml
<eventReceiver ... xmlns="http://wso2.org/carbon/eventreceiver"><from regex="time\s(\w+)"/>
            <to name="meta_timestamp" type="long"/>
      <from ... </>property>
      <mapping customMapping="enable" type="map">
        <property>
            <from nameregex="timestamppowerSaved\s(\w+)"/>
            <to name="meta_timestampisPowerSaverEnabled" type="longbool"/>
        </property>
        <property>
            <from nameregex="isPowerSaverEnabledvalue\s(\w+)\s(\w+)"/>
            <to name="meta_isPowerSaverEnabledhumidity" type="boolfloat"/>
        </property>    <to     <property>
            <from name="idname="sensorValue" type="double"/>
        </property>
   <to name="meta_sensorId" type="int"/> </mapping>
    <to ...  />
</property>eventReceiver>         <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"/>
 
Info
titleEvents 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.

Image Added

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>         <property>
            <from name="humiditytimestamp"/>
            <to name="humiditymeta_timestamp" type="floatlong"/>
        </property>
        <property>
            <from name="sensorValueisPowerSaverEnabled"/>
            <to name="sensorValuemeta_isPowerSaverEnabled" type="doublebool"/>
        </property>
     </mapping>   <property>
 <to ... />
</eventReceiver>          <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>                  
Info
titleEvents 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