Versions Compared

Key

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

...

  1. Start the CEP, log in to its management console, select Event Formatters and click Add Event Formatter.
  2. Enter details in the form that appears and click the Add Event Formatter button at the end of the form. For example,
    The fields in the above configuration are as follows:

    • Event Formatter Name : Property to uniquely identify an event formatter configuration
    • Event Stream (marked as 1 in the screenshot) : Select an event stream (stream name with version) to listen for events.
    • Stream Attributes : Based on the event stream selected earlier, this shows what the attributes available in the stream are. This field is only for reference.
    • Output Event Adaptor Adapter Name (marked as 2 in the screenshot) : Select the event adaptor adapter used to publish events from the CEP. This drop-down list shows the output event adaptorsadapters already created.
    • Output Mapping Type (marked as 3 the screenshot) : Select json mapping type. This drop-down list is populated based on the event adaptor adapter selected earlier. It lists only the mapping types supported by a particular event adaptoradapter. Some event adaptors adapters support multiple types of mappings. Also, see JSON mapping section below.
       
    • Email Address / Subject: Since you selected the email type event adaptoradapter, you need to provide an email address to send emails to. Also specify the email subject.

      JSON Mapping

      Here when you select the json mapping, you will see a textarea which let you to define the template of the output JSON event. Here you can define the template in two manner, they are In-Line and registry based.

      In-Line

      By-default json mapping is enabled for In-Line, Users just need to add the template of the output JSON event  as shown in number "4". 

      Info

      Please note any attribute name need to be mentioned in double curly braces. eg : {{symbol}}

      Registry Based 

      1. Create a plain text content file (resource)  with the name "quotationTemplate" in "config" directory of the registry, (You can create the resource in "governance" directory also)

      2. Then select the resource that you created in registry. First click on the Pick from registry option , then you can see options (Configuration Registry and Governance Registry) to select the registry resource 

      3. Then click on Configuration Registry link, since we have create the resource in config directory, select the specific resource as shown below and click on OK button. 

  3. After an event formatter is successfully created, you can change its configuration and redeploy it. To do this, click the Edit link associated with it.
  4. An XML based editor opens allowing you to edit the event builder configuration from the UI itself, without having to edit the file in the file system. Do your modifications and click Update.
  5. Alternatively,  you can specify an event formatter configuration using an XML file and save it in <PRODUCT_HOME>/repository/deployment/server/eventformatters directory, which is the event formatter deployment directory. Since hot deployment is enabled, you can simply add/remove files to deploy/undeploy from the server.

    Create the XML file with the following JSON mapping event formatter configurations. Event formatter implementation must start with <eventformatter> root element as in the example below.

    Code Block
    languagehtml/xml
    <eventFormatter name="QuotationFormatter" xmlns="http://wso2.org/carbon/eventformatter">
      <from streamName="stockStream" version="1.0.0"/>
      <mapping type="json">
        <inline>{  "quotedata:StockQuoteDataEvent": {    "quotedata:StockSymbol": "{{symbol}}",    "quotedata:LastTradeAmount": "{{price}}"  }}</inline>
      </mapping>
      <to eventAdaptorName="emailAdaptor" eventAdaptorType="email">
        <property name="email.address">[email protected]</property>
        <property name="email.subject">Quotation Details</property>
      </to>
    </eventFormatter>