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

WSO2 CEP allows you to map custom content from registry for the XML, JSON and Text mapping  types. Custom mapping is stored as a registry resource to be used by the publisher instead of being specified as inline input. WSO2 CEP caches this resource at runtime, and the cache is updated after every cache timeout specified in minutes. If caching is not required, specify the cache timeout as 0.

The following tutorial illustrates how to carry out custom mapping using a registry resource.

  1. Log into the WSO2 CEP Management Console.
  2. Define an event stream as follows. For detailed instructions to create event streams, see Understanding Event Streams.

    1. Enter basic information for the stream as follows.

      ParameterValue
      Event Stream Namesensorsteam
      Event Stream Version1.0.0

      Add attributes as follows.

      Attribute CategoryAttribute NameAttribute Type
      Meta DatasensorIdint
       sensorNamestring
       languagestring
      Correlation Datalongitudedouble
       latitudedouble
      Payload DatasensorValuedouble
  3. Add an output mapping template as a registry resource as follows. For more information about the registry, see Registry.
    1. In the Main tab expand the Registry section and click Browse.
    2. Under Tree View, navigate to /_system/config directory and click Detail ViewClick Add Collection. In the Name field, enter Template and click Add. This creates a new sub directory named template in the /_system/config directory.
    3. Navigate to the /_system/config/template sub directory and click Add Resource. Then enter information as shown in the table below, and click Add.

      FieldValue
      MethodCreate Text Content
      Namemessage
      Media Type
      text/plain
      Content
      Welcome
      Sensor {{meta_sensorName}} reports {{sensorValue}} from {{correlation_longitude}}:{{correlation_latitude}}
  4. Create a new publisher as follows. For more information, see Configuring CEP to Create Alerts - Creating event publishers.

    FieldValue
    Event Publisher Namesamplelogger
    Event Sourcesensorstream
    Output Event Adapter Typelogger
  5. Under Mapping Configuration, select Text for the Message Format field. Then click Advanced. This expands the Create a New Event Publisher page to display the Text Mapping section. Select the Pick from Registry option. In the Registry Path field, navigate to the registry location where you saved the registry resource created in step 3.

    In this example, the default value of 15 is left unchanged for the Cache Timeout (in minutes) field. Therefore, this resource will be cached every 15 minutes.

  6. Click Add Event Publisher.
  7. In the Tools tab, click Event Simulator. In the Event Stream Name field, select sensorstream. Enter the following values for the parameters displayed, and then click Send to simulate a single event.

    ParameterValue
    sensorid10
    sensorNameTemperature
    languageen
    longitude79.861256
    latitude6.927131
    sensorValue23.0

     

    The output for this event is logged in the terminal as follows. 

Using custom registry paths

The registry resource path itself can be parameterized using runtime attribute values. e.g., If the event stream to which the logger publisher in the example above is connected has an attribute named meta_language, a different registry source is selected depending on the runtime value of the meta_language attribute.

The following tutorial illustrates how to change the registry resource path from which a custom output mapping is picked based on the value of an attribute.

The sensor stream event stream used in the previous tutorial is also used in this tutorial.

 

  1. Log into the CEP Management Console.

  2. Create two sub directories in the Template directory you created in the previous tutorial, and add a resource to each of these sub directories as described below. For more information about the registry, see Registry.
    1. In the Main tab expand the Registry section and click Browse.
    2. Under Tree View, navigate to the  /_system/config/template sub directory. Create two more sub directories in it named en and fr.
    3. Navigate to the /_system/config/template/en sub directory and click Add Resource. Then enter information as shown in the table below, and click Add.

      FieldValue
      MethodCreate Text content
      Namemessage
      Media Typetext/plain
      Content
      Welcome
      Sensor {{meta_sensorName}} reports {{sensorValue}} from {{correlation_longitude}}:{{correlation_latitude}}
    4. Navigate to the /_system/config/template/fr sub directory and click Add Resource. Then enter information as shown in the table below, and click Add.

      FieldValue
      MethodCreate Text content
      Namemessage
      Media Typetext/plain
      Content
      Bienvenue
      Sensor {{meta_sensorName}} reports {{sensorValue}} from {{correlation_longitude}}:{{correlation_latitude}}
    After adding both the resources, the registry tree view should look as follows.
  3. Delete the publisher named sample logger and redefine it as follows. For more information, see Configuring CEP to Create Alerts - Creating event publishers.

    FieldValue
    Event Publisher Namesamplelogger
    Event Source

    sensorstream

    Output Event Adapter Typelogger

     

  4. Under Mapping Configuration, select Text for the Message Format field. Then click Advanced. This expands the Create a New Event Publisher page to display the Text Mapping section. Select the Pick from Registry option. Then enter information as follows.

    FieldValue
    Registry Pathconf:/template/{{meta_language}}/message
    Cache Timeout (in minutes)15
  5. Log into the CEP Management Console.

  6. In the Tools tab, click Event Simulator. In the Event Stream Name field, select sensorstream. Send three events with the following values.

    ParameterValue for Event 1Value for Event 2Value for Event 3
    sensorid101010
    sensorNameTemperatureTemperatureTemperature
    languageenfrru
    longitude79.86125679.86125679.861256
    latitude6.9271316.9271316.927131
    sensorValue23.0 23.023.0


    The three events are logged as follows. 
    Note that an error is returned for the third event. This is because no output mapping was done for the ru language.

  • No labels