├── .classpath
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
├── org.eclipse.m2e.core.prefs
└── org.eclipse.pde.core.prefs
├── ReadMe.md
├── elasticsearch
└── mapping.json
├── pom.xml
└── src
├── EIP.png
├── kibana.png
└── main
├── java
└── com
│ └── abouchama
│ ├── ByteToJson.java
│ ├── MQTT.java
│ └── MQTT_Producer.java
└── resources
├── OSGI-INF
└── blueprint
│ └── camel-context.xml
└── log4j.properties
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | erms_txp_tool
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.fusesource.ide.project.RiderProjectBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.m2e.core.maven2Builder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.pde.PluginNature
26 | org.eclipse.jdt.core.javanature
27 | org.eclipse.m2e.core.maven2Nature
28 | org.fusesource.ide.project.RiderProjectNature
29 |
30 |
31 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding//src/test/resources=UTF-8
6 | encoding/=UTF-8
7 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
3 | org.eclipse.jdt.core.compiler.compliance=1.7
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.7
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.pde.core.prefs:
--------------------------------------------------------------------------------
1 | BUNDLE_ROOT_PATH=target/classes
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/ReadMe.md:
--------------------------------------------------------------------------------
1 | Camel Example IoT with MQTT Protocol
2 | ====================================
3 | The Business case for the Internet of Things -- indeed for everything becoming network connected.
4 | The example is demonstrating how to get real time and value from IoT Data
5 |
6 | The camel application poll a Topic with mqtt and publish results in real time using elasticsearch.
7 |
8 | >- ** Implementation view: **
9 |
10 | 1. Add mqtt transport to A-MQ:
11 |
12 |
13 |
14 | 2. Then install the Camel Route, we use MQTT Component in JBoss Fuse to poll in the message from broker.
15 | With the built-in component, it will save lots of code implementation time.
16 |
17 | 
18 |
19 | 3. Elasticsearch
20 | create a new index, with the following mapping:
21 |
22 | ```
23 | curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '
24 | {
25 | "tweet" : {
26 | "properties" : {
27 | "event_datetime" : {"type" : "date"},
28 | "pollution_degree" : {"type" : "integer"},
29 | "latitude" : {"type" : "double"},
30 | "longitude" : {"type" : "double"},
31 | "location" : {"type" : "geo_point"}
32 | }
33 | }
34 | }
35 | '
36 | ```
37 |
38 | 4. Kibana Dashboard:
39 |
40 | - Create a visualisation TileMap based on location field
41 | - Create a visualisation metrics based on pollution degree
42 | - Create a visualisation metrics based on pollution degree & event_datetime
43 |
44 | You should obtain the following dashboard:
45 |
46 | >- **Kibana Dashboard:**
47 |
48 | 
49 |
50 |
51 | >- ** Article: **
52 |
53 | You can find the entire article here:
54 |
55 | http://bushorn.com/iot-service-environment-using-apache-camel-jboss-mq/
--------------------------------------------------------------------------------
/elasticsearch/mapping.json:
--------------------------------------------------------------------------------
1 | curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '
2 | {
3 | "tweet" : {
4 | "properties" : {
5 | "event_datetime" : {"type" : "date"},
6 | "pollution_degree" : {"type" : "integer"},
7 | "latitude" : {"type" : "double"},
8 | "longitude" : {"type" : "double"},
9 | "location" : {"type" : "geo_point"}
10 | }
11 | }
12 | }
13 | '
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 | com.abouchama
8 | camel-example-IoT-MQTT
9 | bundle
10 | 1.0.0-SNAPSHOT
11 |
12 | Camel :: Example :: IoT with MQTT
13 | An example that pushes new mqtt messages to a web page using web-socket
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 2.12.0.redhat-610379
19 |
20 |
21 |
22 |
23 | release.fusesource.org
24 | FuseSource Release Repository
25 | http://repo.fusesource.com/nexus/content/repositories/releases
26 |
27 | false
28 |
29 |
30 | true
31 |
32 |
33 |
34 | snapshot.fusesource.org
35 | FuseSource Snapshot Repository
36 | http://repo.fusesource.com/nexus/content/repositories/snapshots
37 |
38 | true
39 |
40 |
41 | false
42 |
43 |
44 |
45 |
46 |
47 |
48 | release.fusesource.org
49 | FuseSource Release Repository
50 | http://repo.fusesource.com/nexus/content/repositories/releases
51 |
52 | false
53 |
54 |
55 | true
56 |
57 |
58 |
59 | snapshot.fusesource.org
60 | FuseSource Snapshot Repository
61 | http://repo.fusesource.com/nexus/content/repositories/snapshots
62 |
63 | true
64 |
65 |
66 | false
67 |
68 |
69 |
70 |
71 |
72 |
73 | org.apache.camel
74 | camel-core
75 | ${camel-version}
76 |
77 |
78 | org.apache.camel
79 | camel-mqtt
80 | ${camel-version}
81 |
82 |
83 | org.apache.camel
84 | camel-websocket
85 | ${camel-version}
86 |
87 |
88 | org.apache.camel
89 | camel-elasticsearch
90 | ${camel-version}
91 |
92 |
93 |
94 | org.slf4j
95 | slf4j-api
96 | 1.6.6
97 |
98 |
99 | org.slf4j
100 | slf4j-log4j12
101 | 1.6.6
102 |
103 |
104 | log4j
105 | log4j
106 | 1.2.17
107 |
108 |
109 | com.googlecode.json-simple
110 | json-simple
111 | 1.1
112 |
113 |
114 |
115 |
116 |
117 |
118 | org.apache.maven.plugins
119 | maven-compiler-plugin
120 | 2.3.2
121 |
122 | 1.7
123 | 1.7
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-surefire-plugin
129 |
130 | pertest
131 | false
132 | true
133 | false
134 |
135 | **/*Test.java
136 |
137 |
138 | src/test/resources
139 |
140 |
141 |
142 |
143 | org.apache.felix
144 | maven-bundle-plugin
145 | 2.4.0
146 | true
147 |
148 |
149 | com.abouchama.*
150 | org.apache.activemq.camel.component,*
151 |
152 |
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/src/EIP.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abouchama/camel-example-IoT-MQTT/67b515f80d82fe86d5c61680e281e644a446be67/src/EIP.png
--------------------------------------------------------------------------------
/src/kibana.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abouchama/camel-example-IoT-MQTT/67b515f80d82fe86d5c61680e281e644a446be67/src/kibana.png
--------------------------------------------------------------------------------
/src/main/java/com/abouchama/ByteToJson.java:
--------------------------------------------------------------------------------
1 | package com.abouchama;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.IOException;
5 | import java.io.ObjectInputStream;
6 | import java.util.Map;
7 |
8 | import org.apache.camel.Exchange;
9 | import org.apache.camel.Message;
10 | import org.apache.camel.Processor;
11 |
12 | /**
13 | * A processor that transform the body from Bytes to Json.
14 | */
15 |
16 | public class ByteToJson implements Processor {
17 |
18 | @Override
19 | public void process(Exchange exchange) throws IOException, ClassNotFoundException {
20 | Message inMessage = exchange.getIn();
21 | if (inMessage != null) {
22 | byte[] bytes = inMessage.getBody(byte[].class);
23 |
24 | ByteArrayInputStream b = new ByteArrayInputStream(bytes);
25 | ObjectInputStream o = new ObjectInputStream(b);
26 | Map map = (Map) o.readObject();
27 | o.close();
28 | exchange.getIn().setBody(map);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/abouchama/MQTT.java:
--------------------------------------------------------------------------------
1 | package com.abouchama;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 |
6 | /**
7 | *
8 | * Benchmark tool entry point.
9 | *
10 | * You could set the number of producers and consumers
11 | *
12 | */
13 | public class MQTT {
14 | private static final int PUBLISHER_POOL_SIZE = 2;
15 |
16 | public static void main(String[] args) {
17 | ExecutorService pool = Executors.newFixedThreadPool(PUBLISHER_POOL_SIZE);
18 |
19 | pool.submit(new MQTT_Producer("Client1"));
20 |
21 | pool.shutdown();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/abouchama/MQTT_Producer.java:
--------------------------------------------------------------------------------
1 | package com.abouchama;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.ObjectOutputStream;
5 | import java.net.URISyntaxException;
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 | import org.fusesource.mqtt.client.BlockingConnection;
11 | import org.fusesource.mqtt.client.MQTT;
12 | import org.fusesource.mqtt.client.QoS;
13 | import org.slf4j.Logger;
14 | import org.slf4j.LoggerFactory;
15 |
16 | /**
17 | * This class only publish MQTT messages to a define topic with a certain frequency.
18 | *
19 |
20 | */
21 | public class MQTT_Producer implements Runnable {
22 |
23 | private static final Logger LOG = LoggerFactory.getLogger(MQTT_Producer.class);
24 |
25 | private String m_clientID;
26 |
27 | public MQTT_Producer(String clientID) {
28 | m_clientID = clientID;
29 | }
30 |
31 | public void run() {
32 | MQTT mqtt = new MQTT();
33 | try {
34 | mqtt.setHost("localhost", 1883);
35 | mqtt.setUserName("admin");
36 | mqtt.setPassword("admin");
37 | } catch (URISyntaxException ex) {
38 | LOG.error(null, ex);
39 | return;
40 | }
41 |
42 | mqtt.setClientId(m_clientID);
43 | BlockingConnection connection = mqtt.blockingConnection();
44 | try {
45 | connection.connect();
46 | } catch (Exception ex) {
47 | LOG.error("Cant't CONNECT to the server", ex);
48 | return;
49 | }
50 |
51 | //TODO loop
52 | try {
53 | //java.util.Date date= new java.util.Date();
54 | Map map = new HashMap();
55 | //Map map = new HashMap();
56 | Date dNow = new Date( );
57 | SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS");
58 | System.out.println("Current Date: " + ft.format(dNow));
59 | map.put("event_datetime", ft.format(dNow));
60 | map.put("pollution_degree",""+new Integer(0));
61 | map.put("latitude", ""+new Double(48.86670000000001));
62 | map.put("longitude", ""+new Double(2.3333000000000084));
63 | /*// Nantes
64 | map.put("location", "47.2183710, -1.5536210");
65 | map.put("pollution_degree",""+new Integer(0));*/
66 |
67 | // Le Havre
68 | map.put("location", "49.4943700, 0.1079290");
69 | map.put("pollution_degree",""+new Integer(1));
70 |
71 |
72 | /*// Paris
73 | map.put("location", "48.8566140, 2.3522219");
74 | map.put("pollution_degree",""+new Integer(9));*/
75 |
76 | /*// Lyon
77 | map.put("location", "45.7640430, 4.8356590");
78 | map.put("pollution_degree",""+new Integer(5));*/
79 |
80 | /*// Lille
81 | map.put("location", "50.6292500, 3.0572560");
82 | map.put("pollution_degree",""+new Integer(5));*/
83 |
84 | /*// Monaco
85 | map.put("location", "43.7384176, 7.4246158");
86 | map.put("pollution_degree",""+new Integer(2));*/
87 |
88 | /*// Marseille
89 | map.put("location", "43.2964820, 5.3697800");
90 | map.put("pollution_degree",""+new Integer(3));*/
91 |
92 | /* // Toulouse
93 | map.put("location", "43.6046520, 1.4442090");
94 | map.put("pollution_degree",""+new Integer(1));*/
95 |
96 | /*// Brest
97 | map.put("location", "48.3903940, -4.4860760");
98 | map.put("pollution_degree",""+new Integer(7));*/
99 |
100 | ByteArrayOutputStream b = new ByteArrayOutputStream();
101 | ObjectOutputStream o=new ObjectOutputStream(b);
102 | o.writeObject(map);
103 | o.close();
104 | byte bytes[]=b.toByteArray();
105 | LOG.info("Publishing");
106 | connection.publish("iot-mqtt", bytes, QoS.AT_MOST_ONCE, false);
107 |
108 | //connection.publish("iot-mqtt", obj.toString().getBytes("utf-8"), QoS.AT_MOST_ONCE, false);
109 | /*connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=48.85837,Longitude=2.294481000000019".getBytes(), QoS.AT_MOST_ONCE, false);
110 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=51.5073509,Longitude=-0.12775829999998223".getBytes(), QoS.AT_MOST_ONCE, false);
111 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=33.9715904,Longitude=-6.849812899999961".getBytes(), QoS.AT_MOST_ONCE, false);
112 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=46.818188,Longitude=8.227511999999933".getBytes(), QoS.AT_MOST_ONCE, false);
113 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=49.815273,Longitude=6.129583000000025".getBytes(), QoS.AT_MOST_ONCE, false);
114 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=53.5510846,Longitude=9.99368179999999".getBytes(), QoS.AT_MOST_ONCE, false);
115 | connection.publish("iot-mqtt", "pollutionDegree=9,Latitude=48.85837,Longitude=2.294481000000019".getBytes(), QoS.AT_MOST_ONCE, false);
116 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=51.5073509,Longitude=-0.12775829999998223".getBytes(), QoS.AT_MOST_ONCE, false);
117 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=33.9715904,Longitude=-6.849812899999961".getBytes(), QoS.AT_MOST_ONCE, false);
118 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=33.9715904,Longitude=-6.849812899999961".getBytes(), QoS.AT_MOST_ONCE, false);
119 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=33.9715904,Longitude=-6.849812899999961".getBytes(), QoS.AT_MOST_ONCE, false);
120 | connection.publish("iot-mqtt", "pollutionDegree=6,Latitude=33.9715904,Longitude=-6.849812899999961".getBytes(), QoS.AT_MOST_ONCE, false);
121 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=46.818188,Longitude=8.227511999999933".getBytes(), QoS.AT_MOST_ONCE, false);
122 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=49.815273,Longitude=6.129583000000025".getBytes(), QoS.AT_MOST_ONCE, false);
123 | connection.publish("iot-mqtt", "pollutionDegree=4,Latitude=53.5510846,Longitude=9.99368179999999".getBytes(), QoS.AT_MOST_ONCE, false);*/
124 |
125 | } catch (Exception ex) {
126 | LOG.error("Cant't PUSBLISH to the server", ex);
127 | return;
128 | }
129 | try {
130 | LOG.info("Disconneting");
131 | connection.disconnect();
132 | LOG.info("Disconnected");
133 | } catch (Exception ex) {
134 | LOG.error("Cant't DISCONNECT to the server", ex);
135 | }
136 | }
137 |
138 | }
--------------------------------------------------------------------------------
/src/main/resources/OSGI-INF/blueprint/camel-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
16 |
17 |
18 |
19 |
20 |
21 | Logs all the incoming MQTT messages. This is just
22 | for verification purpouses.
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # The logging properties used
3 | #
4 | log4j.rootLogger=INFO, out
5 |
6 | # uncomment the following line to turn on Camel debugging
7 | #log4j.logger.org.apache.camel=DEBUG
8 |
9 | # CONSOLE appender not used by default
10 | log4j.appender.out=org.apache.log4j.ConsoleAppender
11 | log4j.appender.out.layout=org.apache.log4j.PatternLayout
12 | log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
13 | #log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
14 |
15 | log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
16 |
--------------------------------------------------------------------------------