Prerequisites
Follow the steps below before starting this MQTT sample configurations.
- Set up the prerequisites required for all samples
Configure WSO2 CEP by adding relevant jars to support MQTT transport.
- Configure sample client by adding relevant jars. See setting up MQTT for MQTT sample clients.
- Start the MQTT-supported server. (E.g. Mosquitto)
Building the sample
Start the WSO2 CEP 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
org.wso2.event.sensor.stream
- An event receiver named
mqttEventReceiver
to fetch events from the configured MQTT server
- An event publisher named
loggerEventPublisher
to log the received messages
Executing the sample
After you view the message on successful connection to the MQTT-supported server on the WSO2 CEP logs in the CLI, navigate to the <CEP_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 <CEP_HOME>/samples/cep/producers/mqtt/build.xml
file.
This builds the MQTT client and publishes the events in the <CEP_HOME>/samples/cep/artifacts/0016/sensordata.txt
file to the mqttEventReceiver
endpoint. You view the details of the events that are sent as shown below.
You view the CEP server receiving the JSON events in the logs of it in the CLI as shown below.