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

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

When events are sent in the wso2event format, it is possible to include arbitrary attributes. Arbitrary attributes are attributes that are not defined in the event stream to which the events are sent.

The following is a sample configuration of an event in the wso2event format with arbitrary attributes.

Code Block
Map<String, String> arbitraryData = new HashMap<>();
arbitrary.put("meterId", "m0011");
arbitrary.put("switchId", "s0023");
arbitrary.put("phaseId", "p0097");

Event event = new Event(streamDefinition.getStreamId(), System.currentTimeMillis(), metaData, correlationData, payloadData, arbitraryData);

The values for arbitrary attributes in events can be accessed for processing by an execution plan. This is done by selecting the Include Arbitrary check box to the following in the attribute list of the import stream.
 arbitraryDataMap Object

For more information, see Creating a Standalone Execution Plan.

 

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.

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

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

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

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