Follow the steps below before starting this MQTT sample configurations.
- Set up the prerequisites required for all samples.
Configure WSO2 DAS by adding relevant jars to support MQTT transport.
- Configure the sample client by adding the relevant jars. For more information, see setting up MQTT for MQTT sample clients.
- Start the MQTT-supported server. (E.g. Mosquitto)
Building the sample
Start the WSO2 DAS server with the sample configuration numbered 0016. For instructions, see Starting sample CEP configurations.
This sample configuration creates the following.
- An event stream with the ID
- An event receiver named
mqttEventReceiverto fetch events from the configured MQTT server
- An event publisher named
loggerEventPublisherto log the received messages.
Executing the sample
After you view the message upon successful connection to the MQTT-supported server in the WSO2 DAS logs in the CLI, navigate to the
<DAS_HOME>/samples/cep/producers/mqtt/ directory, and execute the following Ant command using another tab in the CLI.
ant -Durl=tcp://localhost:1883 -Dtopic=sensordata -Dsn=0016
Replace the value of the
Durl parameter in the above command with your MQTT broker URL accordingly. The other optional parameters that can be used in the above command are defined in the
This builds the MQTT client and publishes the events in the
<DAS_HOME>/samples/cep/artifacts/0016/sensordata.txt file to the
mqttEventReceiver endpoint. The details of the events that are sent are logged as shown below.
The JSON events received by the DAS server are logged as shown below.