Over a million developers have joined DZone.

IoT Using Apache Camel and JBoss A-MQ

DZone 's Guide to

IoT Using Apache Camel and JBoss A-MQ

Here's a simple example of a smart city project that measures air pollution using a combo of sensors, JBoss A-MQ, MQTT, and Kibana.

· IoT Zone ·
Free Resource

This post proposes using IoT to address the problem of degrading air quality in cities.

The idea is that a sensor will measure the air pollution levels and transmit that data. The information will then be shared with the users of the system.

The example demonstrates how to get value from IoT data by using Apache CamelJBoss A-MQ, and Elasticsearch.

The basic architecture of this demo is basically as follows:

There are three common protocols when it comes to IoT messaging — MQTT, AMQP, and STOMP. In this example, all sensor devices use MQTT (which is supported by JBoss A-MQ) to interact and connect. 

Why MQTT? It is an OASIS standard, adopted by various vendor and companies. It is an extremely lightweight transport and is excellent for low-power devices and associated platforms. It supports a publish and subscribe mechanism that we will make use of.

All IoT data collected by the sensors are sent and aggregated reliably in JBoss A-MQ and processed by Apache Camel. After that, data is stocked in Elasticsearch for real-time notifications.

How Can We Implement This?

You have to add the MQTT transport connector to JBoss A-MQ. To do that, you have to add the following line in your Broker.xml:

<transportConnector name=”mqtt” uri=”mqtt://${Hostname}:1883″/>

Then install Camel Route. This route uses built-in components in JBoss Fuse to pull in the message from the broker. With the built-in component, it will save lots of code implementation time.


As you can see from the Camel Route example, after we retrieve messages from the topic IoT, we will process it and store it in Elasticsearch, which will be picked up by Kibana and displayed in a dashboard.

At the Elasticsearch level, you have to create a new index with the following mapping:

curl -XPUT ‘http://localhost:9200/pollutionlevel/_mapping/command’ -d ‘ {“tweet” : { “properties” : { “event_datetime” : {“type” : “date”}, “pollution_degree” : {“type” : “integer”}, “latitude” : {“type” : “double”}, “longitude” : {“type” : “double”}, “location” : {“type” : “geo_point”}}}}‘

At this moment, all data is available in Elasticsearch and we have just to explore and visualize it via Kibana. For that, you have to create some visualizations that will be included in your dashboards.

Below is an example of a custom Dashboard:


I hope that you find this post useful, and good luck with your projects!

iot ,smart cities ,jboss a-mq ,mqtt ,sensor tech ,elasticsearch ,iot data ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}