Versions Compared

Key

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

JSON Event Builder converts the events/streams from an input adaptor /wiki/spaces/PS/pages/10518547 that supports JSON input streams into an event stream that is compatible with the event processor. The event attributes are extracted using JSONPath expressions and are converted to the type specified in the mapping, before sent to the event processor.

...

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

    • Event Builder Name : Property to uniquely identify an event formatter configuration
    • Input Event Adaptor : The input event adaptor used to publish events to the CEP. This drop-down list only displays the adaptors that are already created. In this example, we select an Input JMS Event Adaptor /wiki/spaces/PS/pages/10518554 already created.
    • Topic : The topic to which event publishers send events
    • Input Mapping Type : Select json as the mapping type. This property changes based on the event adaptor selected. It lists only the mapping types supported by a particular event adaptor.
    • Advanced : Map the incoming stream to the outgoing stream received by the event processor. Provide the necessary details in the input fields:
      • Enter the  Input Attribute Name , JSONPath  and  To Stream Data Type  under Properties

        Info

        For the correct properties to show, you must select an event adaptor that supports JSON mapping type.

        Note

        Here, If you not willing to add advanced mapping properties then json event needs to be in a format which can accepted by the CEP. Sample json event format accept by CEP is below. Corresponding stream definition which related to below sample event.

        Code Block
        languagehtml/xml
        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}],
        }
        Code Block
        {
            "event": {
                "metaData": {
                    "tenant_id": "50"         
                },
                "correlationData": {
                    "activity_id": "ID-1"
                },
                "payloadData": {
                    "clientPhoneNo": "0771117673",
                    "clientName": "Mohana",
                    "clientResidenceAddress": "15, Alexdendra road, California",
                    "clientAccountNo": "AC5673"
                }
            }
        }
  3. After a builder is successfully created, you can change its configuration and redeploy it. To do this, click the Edit link associated with it. You can also click the other links associated with it to delete or enable statistics and tracing.
  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,

    Anchor
    step5
    step5
    you can specify an event builder configuration using an XML file and save it in <PRODUCT_HOME>/repository/deployment/server/eventbuilders directory, which is the event builder 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 based event builder configurations. Event builder implementation must start with <eventbuilder> root element and the namespace set to http://wso2.org/carbon/eventbuilder as in the example below:

    Code Block
    languagehtml/xml
    <?xml version="1.0" encoding="UTF-8"?>
    <eventBuilder name="searchStatsJSONBuilder" statistics="disable"
        trace="disable" xmlns="http://wso2.org/carbon/eventbuilder">
        <from eventAdaptorName="httpInputAdaptor" eventAdaptorType="http">
            <property name="topic">searchstats</property>
        </from>
        <mapping customMapping="enable" type="json">
            <property>
                <from jsonPath="ip"/>
                <to name="ip" type="string"/>
            </property>
            <property>
                <from jsonPath="username"/>
                <to name="username" type="string"/>
            </property>
            <property>
                <from jsonPath="searchKey"/>
                <to name="searchKey" type="string"/>
            </property>
        </mapping>
        <to streamName="searchStats" version="1.0.0"/>
    </eventBuilder>