Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.
This documentation is for WSO2 Message Broker version 3.2.0. For the latest documentation, see the documentation for WSO2 Enterprise Integrator.
Skip to end of metadata
Go to start of metadata

This sample demonstrates how WSO2 MB can use the MQTT transport to publish data from running vehicles to a central server and then use that data for analysis.

About the sample

It creates mock vehicles and simulates the functionality of publishing data (such as the current speed, current acceleration and the engine temperature) from the vehicle to a topic hierarchy in MB every second.

Data is published to the topic hierarchy in the following format:

VehicleType/VehicleModel/VehicleId/Sensor

For example, a vehicle of type abc, model xyz and vehicle ID 123 would publish data as shown below to the relevant hierarchies.

  • abc/xyz/123/engintemperature

  • abc/xyz/123/speed

  • abc/xyz/123/acceleration

To publish messages to a hierarchy, use "/" as the hierarchy separator as shown above. 3 MQTT clients will retrieve the real time data published from each vehicle through the broker as follows:

  • Subscribe for +/+/+/enginetemperature to retrieve engine temperature values of all the vehicles. Then calculate the average value each second.

  • Subscribe for car/# to retrieve all sensor data published by cars. Then find and output the car which has the maximum acceleration value for the given seconds.

  • Subscribe for bike/bikeModel/# to retrieve all sensor data for the given bike model. Then output the latest speed readings of the bike.

For subscribing to each use case hierarchy, two wild cards have been used in this sample.

Wild CardDescription
+

This suggest to subscribe to a single level

    • eg :- xyz/+/abc will subscribe to both xyz/1/abc and xyz/2/abc but not xyz/3/def

#

This suggest to subscribe to all subtrees

    • eg :- xyz/# will subscribe to all xyz/1/abc, xyz/2/abc/ and xyz/3/def

The <MB_HOME>/Samples/MqttIoT/src/main/java/org/wso2/sample/mqtt directory has the following classes:

The code of this class is as follows:

package org.wso2.sample.mqtt;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
import org.wso2.sample.mqtt.model.Vehicle;
import java.io.File;
import java.util.concurrent.ConcurrentHashMap;

/**
 * The mqtt client implementation for the sample.
 * This keeps hold of the latest data received in a topic related to sensors.
 */

public class AndesMQTTClient implements MqttCallback {
    private static final Log log = LogFactory.getLog(AndesMQTTClient.class);
    public static final String TEMPERATURE_PREFIX = "E:";
    public static final String SPEED_PREFIX = "S:";
    public static final String ACCELERATION_PREFIX = "A:";
    private MqttClient mqttClient;

    /**
     * Latest temperature readings received from the server <topic, value> *
     */
    private final ConcurrentHashMap<String, String> latestTemperatureReadings = new ConcurrentHashMap<String, String>();

    /**
     * Latest Speed readings received from the server <topic, value> *
     */
    private final ConcurrentHashMap<String, String> latestSpeedReadings = new ConcurrentHashMap<String, String>();
    /**
     * Latest acceleration readings received from the server <topic, value> *
     */
    private final ConcurrentHashMap<String, String> latestAccelerationReadings = new ConcurrentHashMap<String,
            String>();

    /**
     * Create new mqtt client with the given clientId.
     *
     * @param clientId     The unique client Id
     * @param cleanSession Clean previous session data
     * @param userName User Name of the account
     * @param password User Password of the account
     * 
     * @throws MqttException
     */

    public AndesMQTTClient(String clientId, boolean cleanSession, String userName, String password) throws MqttException {
        MqttConnectOptions options = new MqttConnectOptions();
        options.setCleanSession(cleanSession);
        options.setUserName(userName);
        options.setPassword(password.toCharArray());
        mqttClient = new MqttClient(MQTTSampleConstants.BROKER_URL, clientId,
                new MqttDefaultFilePersistence(MQTTSampleConstants.TMP_DIR + File.separator + clientId));
        mqttClient.setCallback(this);
        mqttClient.connect(options);
    }

    /**
     * Subscribe to a topic.
     *
     * @param topic The topic to subscribe
     * @param qos   The quality of service level
     * @throws MqttException
     */
    public void subscribe(String topic, int qos) throws MqttException {
        mqttClient.subscribe(topic, qos);
    }

    /**
     * Un-subscribe from a topic.
     *
     * @param topic The topic to un-subscribe from
     * @throws MqttException
     */
    public void unsubscribe(String topic) throws MqttException {
        mqttClient.unsubscribe(topic);
    }

    /**
     * Send a message to mqtt server.
     *
     * @param topic   The topic to send message to
     * @param message The message string to send
     * @param qos     The quality of service level
     * @throws MqttException
     */
    public void sendMessage(String topic, String message, int qos) throws MqttException {
        mqttClient.publish(topic, message.getBytes(), qos, false);
    }

    /**
     * Disconnect the mqtt client.
     *
     * @throws MqttException
     */
    public void disconnect() throws MqttException {
        mqttClient.disconnect();
    }

    /**
     * Connection lost message received from the server.
     *
     * @param throwable Connection lost cause
     */
    public void connectionLost(Throwable throwable) {
        // We're only logging the connection lost here since this class is only responsible for handling callbacks
        // from server. If client tries to invoke any further operation on server it will create a server error which
        // will then be handled by the client.
        log.warn("Server connection lost.", throwable);
    }

    /**
     * Handle received messages from mqtt server.
     * If the received message is from one of the vehicle sensors, keep the latest one in memory to be retrieved by a
     * third party.
     *
     * @param topic       The topic message received from
     * @param mqttMessage The mqtt message received
     * @throws Exception
     */
    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        String message = mqttMessage.toString();
        String sensorReading = message.substring(2);
        if (message.startsWith(TEMPERATURE_PREFIX)) {
            latestTemperatureReadings.put(topic, sensorReading);
        } else if (message.startsWith(SPEED_PREFIX)) {
            latestSpeedReadings.put(topic, sensorReading);
        } else if (message.startsWith(ACCELERATION_PREFIX)) {
            latestAccelerationReadings.put(topic, sensorReading);
        }
    }
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
    }
    /**
     * Get last temperature readings received.
     *
     * @return Received temperatures <topic, value>
     */
    public ConcurrentHashMap<String, String> getLatestTemperatureReadings() {
        return latestTemperatureReadings;
    }
    /**
     * Get last speed readings.
     *
     * @return Received speed readings <topic, value>
     */
    public ConcurrentHashMap<String, String> getLatestSpeedReadings() {
        return latestSpeedReadings;
    }
    /**
     * Get last acceleration reading.
     *
     * @return Received acceleration readings <topic, value>
     */
    public ConcurrentHashMap<String, String> getLatestAccelerationReadings() {
        return latestAccelerationReadings;
    }
}

The code of this class is as follows:

package org.wso2.sample.mqtt;

/**
 * This holds constants used for the sample.
 */
public class MQTTSampleConstants {
    /**
     * Stop creating instance of this since this is only used to store constants.
     */
    private MQTTSampleConstants() {
    }
    // The URL of the Message Broker
    public static final String BROKER_URL = "tcp://localhost:1883";
    // The temp directory to use for mqtt client
    public static final String TMP_DIR = System.getProperty("java.io.tmpdir");
    /**
     * Credentials to be used when connecting to MQTT server
     */
    public static final String DEFAULT_USER_NAME = "admin";
    public static final String DEFAULT_PASSWORD = "admin";
}

The model directory in the mqtt directory has the following classes:

The code is as follows:

package org.wso2.sample.mqtt.model;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.wso2.sample.mqtt.AndesMQTTClient;
import org.wso2.sample.mqtt.MQTTSampleConstants;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
 * This represents a Vehicle and is responsible for collecting sensor data for itself and sending them to the server.
 */
public class Vehicle {
    private String vehicleId;
    private VehicleModel vehicleModel;
    private AndesMQTTClient mqttClient;
    private double engineTemperature; // Celsius
    private double speed; // km/h
    private double acceleration; // m/s^2
    public static final String ENGINE_TEMPERATURE = "engintemperature";
    public static final String SPEED = "speed";
    public static final String ACCELERATION = "acceleration";
    private final int qos = 0;
    private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
    private final ScheduledFuture statusUpdateSchedule;
    private final Log log = LogFactory.getLog(Vehicle.class);
    /**
     * Create a new vehicle initialising vehicleId, Model and sensor data update process.
     *
     * @param vehicleId    The vehicle Id to create
     * @param vehicleModel The model of the vehicle
     * @throws MqttException
     */
    public Vehicle(final String vehicleId, VehicleModel vehicleModel) throws MqttException {
        setVehicleId(vehicleId);
        setVehicleModel(vehicleModel);
        mqttClient = new AndesMQTTClient(vehicleId, true, 
        						MQTTSampleConstants.DEFAULT_USER_NAME, 
        						MQTTSampleConstants.DEFAULT_PASSWORD);
        // send sensor statuses to the server periodically.
        statusUpdateSchedule = scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                try {
                    // Send temperature reading
                    mqttClient.sendMessage(generateTopicHierarchy(ENGINE_TEMPERATURE),
                            String.valueOf(getEngineTemperature()), qos);
                    // Send speed reading
                    mqttClient.sendMessage(generateTopicHierarchy(SPEED), String.valueOf(getSpeed()), qos);
                    // Send acceleration reading
                    mqttClient.sendMessage(generateTopicHierarchy(ACCELERATION), String.valueOf(getAcceleration()),
                            qos);
                    log.info("Sensor readings of " + vehicleId + " sent to server.");
                } catch (MqttException e) {
                    log.error("Error sending sensor data to server.", e);
                }
            }
        }, 0, 1, TimeUnit.SECONDS);
        log.info("A " + vehicleModel.getVehicleType().getTypeName() + " of model " + vehicleModel.getModelName() + " " +
                "created. Id : " + vehicleId);
    }
    public String getVehicleId() {
        return vehicleId;
    }
    public void setVehicleId(String vehicleId) {
        this.vehicleId = vehicleId;
    }
    public VehicleModel getVehicleModel() {
        return vehicleModel;
    }
    public void setVehicleModel(VehicleModel vehicleModel) {
        this.vehicleModel = vehicleModel;
    }
    public double getEngineTemperature() {
        return engineTemperature;
    }
    public void setEngineTemperature(double engineTemperature) {
        this.engineTemperature = engineTemperature;
        log.info("Engine temperature of " + vehicleId + " updated to " + engineTemperature);
    }
    public double getSpeed() {
        return speed;
    }
    public void setSpeed(double speed) {
        this.speed = speed;
        log.info("Speed of " + vehicleId + " updated to " + speed);
    }
    public double getAcceleration() {
        return acceleration;
    }
    public void setAcceleration(double acceleration) {
        this.acceleration = acceleration;
        log.info("Acceleration of " + vehicleId + " updated to " + acceleration);
    }
    /**
     * Generate the hierarchy the vehicle should publish data to in mqtt.
     *
     * @param leafTopic The leaf of the topic hierarchy
     * @return The topic hierarchy that is feed-able to the broker
     */
    public String generateTopicHierarchy(String leafTopic) {
        return vehicleModel.getVehicleType().getTypeName() + "/" + vehicleModel.getModelName() + "/" + vehicleId +
                "/" + leafTopic;
    }
    /**
     * Stop sending sensor data to the server and disconnect clients.
     *
     * @throws MqttException
     */
    public void stopSensorDataUpload() throws MqttException {
        statusUpdateSchedule.cancel(true);
        scheduledExecutorService.shutdown();
        mqttClient.disconnect();
    }
}

The code is as follows:

package org.wso2.sample.mqtt.model;
/**
 * This represents a Vehicle Model in a given Vehicle Type.
 */
public class VehicleModel {
    private String modelName;
    private VehicleType vehicleType;
    /**
     * Creates a new vehicle model with given name and type.
     *
     * @param name The vehicle model name
     * @param type The vehicle model type
     */
    public VehicleModel(String name, VehicleType type) {
        setModelName(name);
        setVehicleType(type);
    }
    public String getModelName() {
        return modelName;
    }
    public void setModelName(String modelName) {
        this.modelName = modelName;
    }
    public VehicleType getVehicleType() {
        return vehicleType;
    }
    public void setVehicleType(VehicleType vehicleType) {
        this.vehicleType = vehicleType;
    }
}

The code is as follows:

package org.wso2.sample.mqtt.model;
/**
 * This represents a vehicle type.
 * eg :- CAR, BIKE, VAN
 */
public class VehicleType {
    private String typeName;
    /**
     * Initialize a vehicle type in the given name.
     * @param name The vehicle type name
     */
    public VehicleType(String name) {
        setTypeName(name);
    }
    public String getTypeName() {
        return typeName;
    }
    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }
}

This defines the method to call all the other classes mentioned above. The code of this class is as follows:

package org.wso2.sample.mqtt;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.wso2.sample.mqtt.model.Vehicle;
import org.wso2.sample.mqtt.model.VehicleModel;
import org.wso2.sample.mqtt.model.VehicleType;
import java.util.*;
import java.util.concurrent.*;
/**
 * This samples demonstrates how WSO2 Message Broker MQTT can be used to publish data from running vehicles to a
 * central server and use that data to analyze and come to conclusions.
 * <p/>
 * The main class which executes the sample.
 * - Creates mock vehicle types, vehicle models and vehicles
 * - Updates sensor readings periodically in each vehicle with a random value mocking the sensor behaviours
 * - Read sensor data published by all vehicles via mqtt server and generate mock output scenarios.
 * ~ Real time speed of a given vehicle
 * ~ Real time average temperature of all the vehicles
 * ~ Real time maximum speed of a given vehicle type
 */
public class Main {
    private static final List<Vehicle> vehicleList = new ArrayList<Vehicle>();
    private static final Map<vehicleTypes, VehicleType> vehicleTypeMap = new HashMap<vehicleTypes, VehicleType>();
    private static final Set<VehicleModel> vehicleModelSet = new HashSet<VehicleModel>();
    private static final Random random = new Random();
    private static enum vehicleTypes {CAR, BIKE, VAN}
    private static AndesMQTTClient temperatureClient;
    private static AndesMQTTClient carClient;
    private static AndesMQTTClient harleySpeedClient;
    private static final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
    private static ScheduledFuture vehicleStatusUpdater;
    private static ScheduledFuture vehicleStatusProcessor;
    /**
     * Time to run the sample in seconds
     */
    private static final int RUNTIME = 20000;
    private static final Log log = LogFactory.getLog(Main.class);
    /**
     * Executes vehicle population, mock sensor reading update and sensor data reading.
     *
     * @param args main command line arguments
     * @throws InterruptedException
     * @throws MqttException
     */
    public static void main(String[] args) throws InterruptedException, MqttException {
        populateVehicles();
        scheduleMockVehicleStatusUpdate();
        try {
            listenToVehicleSensorStatuses();
            // Let stats publish and stats processing commence for RUNTIME amount of time before exiting the sample
            Thread.sleep(RUNTIME);
            shutdown();
        } catch (MqttException e) {
            log.error("Error running the sample.", e);
        }
    }
    /**
     * Schedule to periodically update sensor readings of all vehicles.
     */
    private static void scheduleMockVehicleStatusUpdate() {
        // Update sensors with random values.
        vehicleStatusUpdater = scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                for (Vehicle vehicle : vehicleList) {
                    vehicle.setAcceleration(random.nextInt(360));
                    vehicle.setSpeed(random.nextInt(200));
                    vehicle.setEngineTemperature(random.nextInt(350));
                }
            }
        }, 0, 500, TimeUnit.MILLISECONDS);
    }
    /**
     * Populate vehicles types with CAR, BIKE and VAN.
     */
    private static void populateVehicleTypes() {
        // CAR
        VehicleType car = new VehicleType(vehicleTypes.CAR.name());
        // BIKE
        VehicleType bike = new VehicleType(vehicleTypes.BIKE.name());
        // VAN
        VehicleType van = new VehicleType(vehicleTypes.VAN.name());
        vehicleTypeMap.put(vehicleTypes.CAR, car);
        vehicleTypeMap.put(vehicleTypes.BIKE, bike);
        vehicleTypeMap.put(vehicleTypes.VAN, van);
    }
    /**
     * Populate vehicle models.
     * - 5 models of type CAR
     * - 5 models of type BIKE
     * - 3 models of type VAN
     */
    private static void populateVehicleModels() {
        populateVehicleTypes();
        VehicleType car = vehicleTypeMap.get(vehicleTypes.CAR);
        String bmwM3 = "BMWM3";
        String carreraGt = "PorscheCarreraGT";
        String mclarenF1 = "McLarnF1";
        String challenger = "DodgeChallenger";
        String mercielago = "LanborginiMercielago";
        vehicleModelSet.add(new VehicleModel(bmwM3, car));
        vehicleModelSet.add(new VehicleModel(carreraGt, car));
        vehicleModelSet.add(new VehicleModel(mclarenF1, car));
        vehicleModelSet.add(new VehicleModel(challenger, car));
        vehicleModelSet.add(new VehicleModel(mercielago, car));
        VehicleType bike = vehicleTypeMap.get(vehicleTypes.BIKE);
        String nightRod = "HarleyDavidsonNightRod";
        String h2r = "KawasakiH2R";
        String scrambler = "DucatiScramblerFullThrottle";
        String vfr = "HondaVFR800XCrossrunner";
        String gsx = "SuzukiGSX-S1000";
        vehicleModelSet.add(new VehicleModel(nightRod, bike));
        vehicleModelSet.add(new VehicleModel(h2r, bike));
        vehicleModelSet.add(new VehicleModel(scrambler, bike));
        vehicleModelSet.add(new VehicleModel(vfr, bike));
        vehicleModelSet.add(new VehicleModel(gsx, bike));
        VehicleType van = vehicleTypeMap.get(vehicleTypes.VAN);
        String odyssey = "HondaOdyssey";
        String grandCaravan = "DodgeGrandCaravan";
        String sedona = "KiaSedona";

        vehicleModelSet.add(new VehicleModel(odyssey, van));
        vehicleModelSet.add(new VehicleModel(grandCaravan, van));
        vehicleModelSet.add(new VehicleModel(sedona, van));
    }
    /**
     * Create mock vehicles, 1 per each model.
     *
     * @throws MqttException
     */
    private static void populateVehicles() throws MqttException {
        populateVehicleModels();
        int i = 0;
        // 1 vehicle per each vehicle model
        for (VehicleModel vehicleModel : vehicleModelSet) { //todo : i++
            vehicleList.add(new Vehicle("Vehicle" + i++, vehicleModel));
        }
    }
    /**
     * Read vehicle sensor updates from mqtt and output real time values.
     *
     * @throws MqttException
     */
    private static void listenToVehicleSensorStatuses() throws MqttException {
        temperatureClient = new AndesMQTTClient("temperatureClient", true, MQTTSampleConstants.DEFAULT_USER_NAME, MQTTSampleConstants.DEFAULT_PASSWORD);
        temperatureClient.subscribe("+/+/+/" + Vehicle.ENGINE_TEMPERATURE, 1);
        carClient = new AndesMQTTClient("carClient", true, MQTTSampleConstants.DEFAULT_USER_NAME, MQTTSampleConstants.DEFAULT_PASSWORD);
        carClient.subscribe(vehicleTypes.CAR.name() + "/#", 1);
        harleySpeedClient = new AndesMQTTClient("harleySpeedClient", true, MQTTSampleConstants.DEFAULT_USER_NAME, MQTTSampleConstants.DEFAULT_PASSWORD);
        harleySpeedClient.subscribe(vehicleTypes.BIKE.name() + "/HarleyDavidsonNightRod/#", 1);
        // Print real time sensor data each second
        vehicleStatusProcessor = scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                {
                    StringBuilder outputString = new StringBuilder();
                    // Print the speed of Harley
                    ConcurrentHashMap<String, String> latestHarleyReadings = harleySpeedClient.getLatestSpeedReadings();
                    for (Map.Entry<String, String> entry : latestHarleyReadings.entrySet()) {
                        String latestReading = entry.getValue();
                        outputString.append("Latest Harley Speed Reading : ").append(latestReading);
                    }
                    // Print the average temperature of all vehicles
                    ConcurrentHashMap<String, String> latestTemperatureReadings = temperatureClient
                            .getLatestTemperatureReadings();
                    double totalTemperaturesSum = 0;
                    for (Map.Entry<String, String> entry : latestTemperatureReadings.entrySet()) {
                        String latestReading = entry.getValue();
                        if (!StringUtils.isEmpty(latestReading)) {
                            totalTemperaturesSum = totalTemperaturesSum + Double.parseDouble(latestReading);
                        }
                    }
                    outputString.append("\tLatest Average Temperature of All vehicles : ").append
                            (totalTemperaturesSum / latestTemperatureReadings.size());
                    // Print the CAR which has the maximum acceleration at the moment
                    ConcurrentHashMap<String, String> latestCarAccelerationReadings = carClient
                            .getLatestSpeedReadings();
                    double maxAcceleration = 0;
                    String maxAccelerationVehicle = "Undefined";
                    for (Map.Entry<String, String> entry : latestCarAccelerationReadings.entrySet()) {
                        String latestReading = entry.getValue();
                        if (latestReading != null && !"".equals(latestReading)) {
                            double latestAcceleration = Double.parseDouble(latestReading);
                            if (maxAcceleration < latestAcceleration) {
                                maxAcceleration = latestAcceleration;
                                maxAccelerationVehicle = entry.getKey();
                            }
                        }
                    }
                    outputString.append("\tCurrent Max car acceleration : ").append(maxAcceleration).append(" in ")
                            .append(maxAccelerationVehicle.replace("/speed", ""));
                    log.info(outputString);

                }
            }
        }, 0, 1, TimeUnit.SECONDS);
    }
    /**
     * Disconnect all mqtt clients and stop invoked schedules.
     *
     * @throws MqttException
     */
    private static void shutdown() throws MqttException {
        log.info("Stopping sample");
        temperatureClient.disconnect();
        carClient.disconnect();
        harleySpeedClient.disconnect();
        for (Vehicle vehicle : vehicleList) {
            vehicle.stopSensorDataUpload();
        }
        vehicleStatusUpdater.cancel(true);
        vehicleStatusProcessor.cancel(true);
        scheduledExecutorService.shutdown();
    }
}

Prerequisites

Before you build the sample, the prerequisites for MB samples should be in place.

Building the sample

If you are building an MQTT sample for the first time, you need to build the sample using Maven. This will download the Maven dependencies needed for your MQTT samples. Once the dependencies are downloaded, you can build any of the MQTT samples using either Maven or Ant.

Using Maven:
  1. Navigate to the MqttIot sample folder in the <MB_HOME>/samples directory.
  2. Execute the mvn clean install command to build and run the sample.
  3. If the build is successful, the output will be printed in the terminal as shown below.
Using Ant:

Be sure that the Maven dependencies required for MQTT samples are already downloaded as explained here.

  1. Navigate to the MqttIot sample folder in the <MB_HOME>/samples directory.

  2. Execute the ant command to build and run the sample.

  3. If the build is successful, the output will be printed in the terminal as shown below.

Analyzing the output

Following is the output is printed in the terminal if the sample is successfully executed:

     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle12 updated to 74.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle12 updated to 254.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle0 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle1 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle2 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle3 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle4 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle5 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle6 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle7 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle8 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle9 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle10 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle11 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle0 updated to 34.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle0 updated to 0.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle0 updated to 181.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle1 updated to 229.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle1 updated to 78.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle1 updated to 176.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle2 updated to 95.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle2 updated to 37.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle2 updated to 56.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle3 updated to 59.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle3 updated to 44.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle3 updated to 168.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle4 updated to 97.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle4 updated to 182.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle4 updated to 225.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle5 updated to 200.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle5 updated to 51.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle5 updated to 256.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle6 updated to 5.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Sensor readings of Vehicle12 sent to server.
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle6 updated to 145.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle6 updated to 284.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle7 updated to 28.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle7 updated to 142.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle7 updated to 296.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle8 updated to 22.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle8 updated to 13.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle8 updated to 157.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle9 updated to 185.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle9 updated to 24.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle9 updated to 249.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle10 updated to 357.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle10 updated to 180.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle10 updated to 201.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle11 updated to 207.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle11 updated to 8.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle11 updated to 306.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Acceleration of Vehicle12 updated to 328.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Speed of Vehicle12 updated to 85.0
     [java] INFO  [org.wso2.sample.mqtt.model.Vehicle] - Engine temperature of Vehicle12 updated to 0.0
  • No labels