MQTT event adaptor is an internal event adaptor that comes with WSO2 CEP.
Prerequisites
Follow the steps below before starting the input MQTT event adaptor configuration.
- Download the MQTT client library (
mqtt-client-0.4.0.jar
). - Add the file to
<PRODUCT_HOME>/repository/components/lib/
directory.
Configuring Input MQTT Event Adaptor
Follow the below steps to configure the input MQTT adaptor using the management console or using an xml file.
Log in to the CEP management console, go to Configure --> Event Processor Configs --> Input Event Adaptors and click Add Input Event Adaptor. T hen select 'mqtt' as the Event Adaptor Type.
Enter details in the form that appears and click Add Event Adaptor button at the end of the form. For example,
Following values are used in the configuration above (For example):Event Adaptor Name : mqttInputEventAdaptor Event Adaptor Type : mqtt Broker Url : tcp://localhost:1883 Clean Session : true Keep Alive : 70000
- After a adapter is successfully added, if you need, 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 it or enable statistics and tracing.
- An XML based editor opens allowing you to edit the event adaptor configuration from UI itself, without having to edit the file in the file system. Do your modifications and click Update.
Alternatively, you can specify an event adaptor configuration using an XML file and save it in
<PRODUCT_HOME>/repository/deployment/server/inputeventadaptors
directory, which is the Input event adaptor 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 MQTT event adaptor configurations. Input event adaptor implementation must start with<inputEventAdaptor>
root element.<inputEventAdaptor name="mqttInputEventAdaptor" statistics="disable" trace="disable" type="mqtt" xmlns="http://wso2.org/carbon/eventadaptormanager"> <property name="cleanSession">true</property> <property name="url">tcp://localhost:1883</property> <property name="keepAlive">70000</property> </inputEventAdaptor>
Configuring Input MQTT Event Adaptor Message Properties
The configured Input Event Adaptors will be used in Event Builders, with Input Event Adaptor message properties, Event Builders will be able to extract data from the incoming events to build the event streams. Following are the Input MQTT Event Adaptor specific message properties.
- Topic : The topic that will be used to receive messages on the mqttInputAdaptor
- Client Id : Unique client id for communication (You cannot have duplicated client ids for same mqtt broker)
- Input Mapping Type: The incoming event type to be mapped. The Input JMS Event Adaptor supports XML, Json and text mappings.