Receiving XML events via MQTT
Purpose¶
This application demonstrates how to configure WSO2 Integrator: SI Tooling to receive events to the SweetProductionStream via MQTT transport in XML format and log the events in LowProductionAlertStream to the output console.
Prerequisites¶
- Save this sample.
Siddhi App ReceiveMQTTInXMLFormat successfully deployedmessage would be shown in the console. -
Before running this MQTT sample, set up
mosquittoserver which supports MQTT. This can be done by the following commands:sudo apt-get update sudo apt-get install mosquitto -
Install
mosquittoclient packages by executing following command.sudo apt-get install mosquitto-clients -
After the set up ,start the
mosquittoserver by running the following command.sudo service mosquitto start
Executing the Sample¶
-
Start the Siddhi application by clicking on 'Run', the following messages would be shown on the console.
ReceiveMQTTInXMLFormat.siddhi - Started Successfully!
Testing the Sample¶
Option 1: Publish events with the command line publisher¶
Open a terminal and publish events using following command. (The values for name and amount attributes can be changed as desired).
mosquitto_pub -t 'mqtt_topic_input' -m '<events><event><name>sugar</name><amount>300.0</amount></event></events>'
Option 2: Publish events with mqtt sample client¶
- Open a terminal and navigate to
<SI-Tooling-Home>/samples/sample-clients/mqtt-client. -
Run the following command in the terminal:
antIf you want to publish custom number of events, you need to run
antcommand as follows.ant -DnoOfEventsToSend=5
Viewing the Results¶
See the output. Following message would be shown on the console.
ReceiveHTTPInXMLFormatWithDefaultMapping : LowProducitonAlertStream : Event{timestamp=1511938781887, data=[sugar, 300.0], isExpired=false}
Note¶
- Stop this Siddhi application.
-
Stop the
mosquittoserver using following command once you are done with the execution.sudo service mosquitto stop
@App:name("ReceiveMQTTInXMLFormat")
@App:description('Receive events via MQTT transport in XML format and view the output on the console.')
@source(type='mqtt', url= 'tcp://localhost:1883',topic='mqtt_topic_input', @map(type='xml'))
define stream SweetProductionStream (name string, amount double);
@sink(type='log')
define stream LowProductionAlertStream (name string, amount double);
-- passthrough data in the SweetProductionStream into LowProducitonAlertStream
@info(name='query1')
from SweetProductionStream
select *
insert into LowProductionAlertStream;