Skip to content

API Docs - v1.0.17

Sink

mqtt (Sink)

The MQTT sink publishes the events to an MQTT broker

Syntax

@sink(type="mqtt", url="<STRING>", username="<STRING>", password="<STRING>", client.id="<STRING>", topic="<STRING>", quality.of.service="<STRING>", clean.session="<BOOL>", message.retain="<STRING>", keep.alive="<INT>", connection.timeout="<INT>", @map(...)))

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
url The URL of the MQTT broker. It is used to connect to the MQTT broker It is required to specify a valid URL here. STRING No No
username The username to be provided when the MQTT client is authenticated by the broker. null STRING Yes No
password The password to be provided when the MQTT client is authenticated by the broker. empty STRING Yes No
client.id A unique ID for the MQTT client. The server uses this to identify the client when it reconnects. If you do not specify a client ID, the system automatically generates it. generated by the system STRING Yes No
topic The topic to which the events processed by WSO2 SP are published via MQTT. This is a mandatory parameter. STRING No Yes
quality.of.service The quality of service provided by the MQTT client. The possible values are as follows.0: The MQTT client sends each event only once. It does not receive an acknowledgement when an event is delivered, and the events are not stored. Events may get lost if the MQTT client is disconnected or if the server fails. This is the fastest method in which events are received via MQTT.1: The MQTT client sends each event at least once. If the MQTT client does not receive an acknowledgement to indicate that the event is delivered, it sends the event again.2: The MQTT client sends each event only once. The events are stored until the WSO2 SP receives them. This is the safest, but the slowest method of receiving events via MQTT. 1 STRING Yes Yes
clean.session This is an optional paramater. If this parameter is set to true, the subscriptions made by the MQTT client during a session expire when the session ends,and they need to be recreated for the next session.
If this parameter is set to false, all the information relating to the MQTT client's connection to the broker (e.g., the specific topics to which the client has subscribed) are saved after a session. Thus, when a session ends and restarts, the connection is re-established with the same information.
The default value is true.
true BOOL Yes No
message.retain If this parameter is set to true, the last message sent from the topic to which WSO2 SP publishes events is retained until the next message is sent. false STRING Yes Yes
keep.alive The maximum number of seconds the connection between the MQTT client and the broker should be maintained without any events being transferred. Once this time interval elapses without any event transfers, the connection is dropped. The default value is 60. 60 INT Yes No
connection.timeout The maximum number of seconds that the MQTT client should spend attempting to connect to the MQTT broker. Once this time interval elapses, a timeout takes place. 30 INT Yes No

Examples EXAMPLE 1

@sink(type='mqtt', url= 'tcp://localhost:1883', topic='mqtt_topic', clean.session='true', message.retain='false', quality.of.service= '1', keep.alive= '60',connection.timeout='30'@map(type='xml'))Define stream BarStream (symbol string, price float, volume long);

This query publishes events to a stream named BarStream via the MQTT transport. The events are published to a topic named mqtt_topic located at tcp://localhost:1883.

Source

mqtt (Source)

The MQTT source receives the events from an MQTT broker

Syntax

@source(type="mqtt", url="<STRING>", username="<STRING>", password="<STRING>", client.id="<STRING>", topic="<STRING>", quality.of.service="<STRING>", clean.session="<BOOL>", keep.alive="<INT>", connection.timeout="<INT>", @map(...)))

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
url The URL of the MQTT broker. It is used to connect to the MQTT broker. It is required to specify a valid URL here. STRING No No
username The username to be provided when the MQTT client is authenticated by the broker. null STRING Yes No
password The password to be provided when the MQTT client is authenticated by the broker. empty STRING Yes No
client.id A unique ID for the MQTT client. The server uses this to identify the client when it reconnects. If you do not specify a client ID, the system automatically generates it. STRING No No
topic The topic from which WSO2 SP receives events via MQTT. Multiple topics can be specified as a list of comma separated values.This is a mandatory parameter. STRING No No
quality.of.service The quality of service provided by the MQTT client. The possible values are as follows.0: The MQTT client sends each event to WSO2 SP only once. It does not receive an acknowledgement when an event is delivered, and the events are not stored.Events may get lost if the MQTT client is disconnected or if the server fails.This is the fastest method in which events are received via MQTT.1: The MQTT client sends each event to WSO2 SP at least once. If the MQTT client does not receive an acknowledgement to indicate that the event is delivered, it sends the event again.2: The MQTT client sends each event to WSO2 SP only once. The events are stored until the WSO2 SP receives them. This is the safest, but the slowest method of receiving events via MQTT. 1 STRING Yes No
clean.session This is an optional paramater. If this parameter is set to true, the subscriptions made by the MQTT client during a session expire when the session ends,and they need to be recreated for the next session.
If this parameter is set to false, all the information relating to the MQTT client's connection to the broker (e.g., the specific topics to which the client has subscribed) are saved after a session. Thus, when a session ends and restarts, the connection is re-established with the same information.
The default value is true.
true BOOL Yes No
keep.alive The maximum number of seconds the connection between the MQTT client and the broker should be maintained without any events being transferred. Once this time interval elapses without any event transfers, the connection is dropped. The default value is 60. 60 INT Yes No
connection.timeout The maximum number of seconds that the MQTT client should spend attempting to connect to the MQTT broker. Once this time interval elapses, a timeout takes place. 30 INT Yes No

Examples EXAMPLE 1

@source(type='mqtt', url= 'tcp://localhost:1883', topic='mqtt_topic', clean.session='true',quality.of.service= '1', keep.alive= '60',connection.timeout='30'@map(type='xml'))Define stream BarStream (symbol string, price float, volume long);

This query receives events from the mqtt_topic topic via MQTT,and processes them to the BarStream stream.