Introduction
This sample demonstrates how to publish JSON events via MQTT transport. This sample does not do any processing on the outgoing event. Events are generated using an input event file and the event simulator.
Prerequisites
Follow the steps below before starting the output MQTT event publisher configuration.
- 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 0066. For instructions, see Starting sample CEP configurations. This sample configuration does the following.
- Creates a stream named
org.wso2.event.sensor.stream
:1.0.0.
- Creates an event publisher named
mqttEventPublisher.
- Load the events stored in the
<CEP_HOME>/samples/cep/artifacts/0066/eventsimulatorfiles/events.csv
file to the event simulator.
Executing the sample
Follow the steps below to execute the sample.
Navigate to the
<CEP_HOME>/samples/cep/consumers/mqtt/
directory, and execute the following Ant command using another tab in the CLI:ant -Durl=tcp://localhost:1883 -Dtopic=sensordata -Dsn=066
The other optional parameters that can be used in the above command are defined in the<CEP_HOME>/samples/cep/consumers/mqtt/build.xml
file.This builds the MQTT client which fetches the published events in the
<CEP_HOME>/samples/cep/artifacts/0066/eventsimulatorfiles/events.csv
file from theeventPublisher
endpoint as shown below.- Log in to the management console.
- Click Tools, and then click Event Simulator.
- Click Play on the corresponding event stream as shown below, to send the events in the
<CEP_HOME>/samples/cep/artifacts/0066/eventsimulatorfiles/events.csv
file to the publisher.
You view the JSON events that are published to the CEP server in the logs of the consumer terminal as shown below.