# Event Publisher

## Configuring WSO2Event Event Publisher

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

Hence WSO2Event has three data types (Meta, Correlation and Payload), the CEP back end runtime event attributes can be mapped to any one of them by adding the mapping configuration under their type names.

### 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 Publisher menu.

2. The Create a New Event Publisher window opens, using which you can configure new event publishers. Enter the following details in the form to create a wso2Event mapping based event publisher as shown in the screenshot below.

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

- Event Publisher Name - Property that used to uniquely identify a event publisher 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 Event Adapter Name - Event adapter which you going to use to publish the events from CEP. (Output Event Adapters which are created are listed here). It is numbered as "2". Based on the Event Adapter that selected sections "3", "4" and "5" will change accordingly.
- Output Mapping Type - This property can be change based on the event adapter selected. Some event adapters can support for multiple types of mappings. User can select the required mapping type from the list. Is is numbered as "3".
- Stream Definition - Since, you have selected WSO2Event type event adapter "wso2EventSender"; you need a stream to send events from CEP.
- Stream Version - Version of the event stream.

##### WSO2Event Mapping

WSO2Event contains three types of data properties. They are Meta Data, Correlation Data and Payload Data. Each data property needs to have

- Name - The attribute name to which the event data will be mapped when creating the output WSO2Event
- Value Of - The attribute/property name from which the data element to be mapped
- Type - Type of the element that is being mapped. This can be either of java.lang.String, java.lang.Integer, java.lang.Long, or java.lang.Double.

3. After adding details click the Add Event Publisher button. The Available Event Publisher page will open. To view event publisher configurations, click on the event publisher name. To delete event publisher, click the Delete button.

Editing Event Publisher Configuration through the Management Console

By Clicking the Edit button of the relevant event publisher, you will able to edit the event publisher 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 publisher configuration from UI without opening the configuration file in the file system.

### Configuring through a xml File

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

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

    <eventPublisher name="StatisticsPublisher" xmlns="http://wso2.org/carbon/eventpublisher">
            <from streamName="statisticsStream" version="1.0.0"/>
            <mapping type="wso2event">
                <metaData>
                    <property>
                        <from name="ipAddress"/>
                        <to name="ipAdd" type="string"/>
                    </property>
                </metaData>
                <payloadData>
                    <property>
                        <from name="user"/>
                        <to name="username" type="string"/>
                    </property>
                </payloadData>
            </mapping>
            <to eventAdapterType="wso2EventSender" eventAdapterType="wso2event">
                <property name="stream">statisticsOutStream</property>
                <property name="version">1.0.0</property>
                </to>
        </eventPublisher>

For more details on creating different types of event publishers, Please refer the official documentation Here.