WSO2 Complex Event Processor is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.
||
Skip to end of metadata
Go to start of metadata

MQTT event publisher is used to send events to a MQTT broker based on the configurations you provide. You can configure it with XML, JSON, and text output mapping types.

Prerequisites 

Follow the steps below before starting the output MQTT event adapter configuration. 

  1. Configure WSO2 CEP by adding relevant libraries to support MQTT transport.

  2. Start the MQTT-supported server.

Creating a MQTT event publisher

For instructions on creating a MQTT event publisher, see Configuring CEP to Create Alerts.

Configuring global properties

The following global properties can be set for the MQTT event publisher type in the <CEP_HOME>/repository/conf/input-event-adapters.xml file. These properties apply to all the publishers of the mqtt type. If a global property available by default is removed, the default value of the property is considered.

Custom properties cannot be added as global properties.

Property KeyDescriptionData TypeDefault Value
minThreadThe minimum number of threads (including idle threads) that should be available in the thread pool at a given time.Integer8
maxThreadThe maximum number of threads (including idle threads) that should be available in the thread pool at a given time.Integer100
keepAliveTimeInMillisThe maximum number of milliseconds that idle threads should be kept alive when the total number of threads in the pool exceeds the number of cores in the machine.Integer20000
jobQueueSizeThe maximum number of milliseconds that idle threads should be kept alive when the total number of threads in the pool exceeds the number of cores in the machine.Integer10000
connectionKeepAliveIntervalThe time interval in milliseconds at which a check should be carried out to identify inactive threads.Integer60

Configuring adapter properties

Specify the Static and Dynamic Adapter Properties, when creating a MQTT event publisher using the management console as shown below.

MQTT event publisher

After entering the above adapter properties, select  the  Message Format   which you want to apply on the published events . Also, click  Advanced  to define custom output mappings based on the  Message Format  you selected. For more information on custom output mapping types, see  Publishing Events in Various Event Formats .

You can also d efine the respective adapter properties of the event publisher based on the transport type within the  <to>  element of the event publisher configuration in the <PRODUCT_HOME>/repository/deployment/server/eventpublishers/ directory as follows.

<eventPublisher name="MQTTOutputEventAdapter" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
  ......................
  <to eventAdapterType="mqtt">
    <property name="topic">sensordata</property>
    <property name="username">mqtt-user</property>
    <property name="qos">1</property>
    <property name="password">mqtt-password</property>
    <property name="clientId">test-client</property>
    <property name="url">tcp://localhost:1883</property>
    <property name="cleanSession">true</property>
  </to>
</eventPublisher>

The above adapter properties are described below.

Static adapter properties  

Adapter Property
Description
Configuration file propertyExample

Client Id

Client identifier is used by the server to identify a client when it reconnects, It used for durable subscriptions or reliable delivery of messages is required

clientId

test-client

Broker Url

MQTT broker URL. The same URL can be used f or WSO2 MB when offset=0

url
 tcp://localhost:1883
Username Username of the broker
username

mqtt-user

Password Password of the broker
password

mqtt-password

Clean Session Whether to persist topic subscriptions and acknowledge positions across client sessions
cleanSession
true/false
Quality of Service

Quality of service for delivering messages between clients and servers. There are three QoS levels in MQTT are as follows.

  • At most once (0)
  • At least once (1)
  • Exactly once (2)
qos
0,1,2

Dynamic adapter properties 

Adapter Property
Description
Configuration file propertyExample

Topic

 The topic that will be used to send messages to MQTT broker.

topic
sensordata

Related samples

For more information on mqtt event publisher type, see the following sample.

  • No labels