This documentation is for WSO2 CEP 3.0.0. View the home page of the latest release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

This will convert the events which coming from Siddhi in to JSON events according to the mapping configurations.

CEP back end runtime event data can be injected to the output as json just by adding the appropriate back end runtime event attribute names in double curly braces ( E.g {{price}} ) into the output json template.

Configuring through the Management Console UI

1. Log in to the CEP management console and select the Main menu in the left hand side of the screen. Then select the Add menu item under Event Formatter menu.

2. The Create a New Event Formatter window opens, using which you can configure new event formatters. Enter the following details in the form to create a json mapping based event formatter as shown in the screenshot below.

Here, there are several properties that need to be filled when creating a event formatter. User interface is divided in to 3 main components (From, Mapping and To) except the event formatter name to give more understanding to the user.

  • Event Formatter Name - Property that used to uniquely identify a event formatter configuration.
  • Event Stream - Can select a event stream (Stream name with version) where you going to listen for events, It is numbered as "1".
  • Stream Attributes - Based on the event stream selected, It shows what are the attributes available at that stream. (It is only for reference when creating output mapping)
  • Output Transport Adaptor Name - Transport adaptor which you going to use to publish the events from CEP. (Output Transport Adaptors which are created are listed here). It is numbered as "2". Based on the Transport Adaptor that selected sections "3", "4" and "5" will change accordingly.
  • Output Mapping Type - This property can be change based on the transport adaptor selected. Some transport adaptors can support for multiple types of mappings. User can select the required mapping type from the list. Is is numbered as "3"
  • Email Address - Since, you have selected email type transport adaptor "emailAdaptor"; you need to provide an email address which used to send emails. 
  • Subject - Subject of the email.

 

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

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 adding details click the Add Event Formatter button. The Available Event Formatter page will open. To view event formatter configurations, click on the event formatter name. To delete event formatter, click the Delete button.

 

Editing Event Formatter Configuration through the Management Console

By Clicking the Edit button of the relevant event formatter, you will able to edit the event formatter configuration and redeploy it. When you click the Edit button, it will redirect to a xml based editor window which allow you to edit the event formatter configuration from UI without opening the configuration file in the file system.

Configuring through a xml File

You can specify a event formatter configuration through in a xml file and deploy it in the deployment directory in the server. Event Formatter deployment directory is available at <CARBON_HOME>/repository/deployment/server/eventformatters . This is an hot deployment directory, then it is easy to deploy and undeploy an event formatter configuration.

1. Create a xml file and enter the following json mapping event formatter configurations inside the above mentioned hot deployment directory. Event formatter implementation needs to be start with "eventformatter" root element.

<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 transportAdaptorName="emailAdaptor" transportAdaptorType="email">
    <property name="email.address">[email protected]</property>
    <property name="email.subject">Quotation Details</property>
  </to>
</eventFormatter>
                                    
  • No labels