XML Event Formatter
XML event formatter converts the events coming from Siddhi to XML events according to the mapping configurations. You can inject the CEP's back-end runtime event data to the output as XML, by adding the appropriate back-end runtime event attribute names in double curly braces (e.g., {{price}}) into the output XML template.
You can configure through the management console as explained below or by manually adding an XML file as explained in step 5.
- Start the CEP, log in to its management console, select Event Formatters and click Add Event Formatter.
- 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
- Stream Attributes : Based on the event stream selected, this shows what the attributes available in the stream are. This field is only for reference.
- Output Event Adapter Name :Â Select the event adapter used to publish events from the CEP. This drop-down list shows the output event adapters already created.
- Output Mapping Type : Select
xml
mapping type. This drop-down list is populated based on the event adapter selected earlier. It lists only the mapping types supported by a particular event adapter. Some event adapters support multiple types of mappings. Also, see XML Mapping section below. - Header : Optional property, here user can add necessary jms header properties with comma ( , ) separated
- Destination : Since you selected jms type event adapter, you need a Destination that tells when output events needs to send.
Advanced Mapping OptionXML Mapping
When you select theÂ
xml
 mapping, you see a text area to define an in-line or a registry-based template of the output XML event.In-line : XML mapping is enabled for in-line templates by default. You must add the template of the output XML event as shown in the example above. Note that any attribute name must be in double curly braces. E.g., {{symbol}}.Â
Registry-based : Follow the steps below to create a registry-based template.
Step 1: Create a plain text content file (resource) in either the
config
or thegovernance
directory of the registry. For more information, see For example,Step 2: 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.Â
Â
Here, If you not willing to add advanced mapping properties then CEP will send xml events with all the attributes which defined in the stream definition. Here, output xml event will be in a predefined event format as shown below.
StreamDefinition{ streamId='loanRequestStream:1.0.0', name='loanRequestStream', version='1.0.0', nickName='loanRequest', description='Stream which contains events related to loan request', tags=null, metaData=[Attribute{name='tenant_id', type=INT}], correlationData=[Attribute{name='activity_id', type=STRING}], payloadData=[Attribute{name='clientPhoneNo', type=STRING}, Attribute{name='clientName', type=STRING}, Attribute{name='clientResidenceAddress', type=STRING}, Attribute{name='clientAccountNo', type=STRING}], }
<events> <event> <metaData> <tenant_id>2</tenant_id> </metaData> <correlationData> <activity_id>ID5</activity_id> </correlationData> <payloadData> <clientPhoneNo>0771117673</clientPhoneNo> <clientName>Mohanadarshan</clientName> <clientResidenceAddress>15, Alexendra road, California</clientResidenceAddress> <clientAccountNo>ACT5673</clientAccountNo> </payloadData> </event> <events>
- 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.
- 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.
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 XML mapping event formatter configurations. Event formatter implementation must start with<eventformatter>
root element as in the example below.<eventFormatter name="xmlEventFormatter" xmlns="http://wso2.org/carbon/eventformatter"> <from streamName="stockStream" version="1.0.0"/> <mapping type="xml"> <inline> <quotedata:StockQuoteDataEvent xmlns:quotedata="http://ws.cdyne.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <quotedata:StockSymbol>{{symbol}}</quotedata:StockSymbol> <quotedata:LastTradeAmount>{{price}}</quotedata:LastTradeAmount> </quotedata:StockQuoteDataEvent> </inline> </mapping> <to eventAdaptorName="jmsOutputEventAdaptor" eventAdaptorType="jms"> <property name="topic">FastMovingStockQuotes</property> <property name="transport.jms.Header">JMSPriority:4,JMSExpiration:5000</property> </to> </eventFormatter>