jax 2014 - m2m for java developers with mqtt
DESCRIPTION
Mobile devices like smartphones and tablet computers became an integral part of our modern world and single-board computers like Raspberry Pi are cheaper today than at any time before. Simple and open Machine-to-Machine (M2M) protocols like MQTT enable these devices to communicate in an efficient manner, even in scenarios with unreliable and instable networks. This talk shows how different Java MQTT libraries can be utilized for professional and personal projects to build efficient and scalable solutions for (mobile) devices. You will also see how modern technologies like WebSocket can be used in conjunction with MQTT to build real time-push services to bring data from sensor hardware to browsers in a scalable manner.TRANSCRIPT
![Page 1: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/1.jpg)
Dominik Obermaier | dc-square GmbH
M2M for Java Developers with MQTT
![Page 2: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/2.jpg)
About meHi, I’m Dominik Obermaier.• CTO of dc-square
• HiveMQ architect
• helped standardizing MQTT at OASIS
• Speaker and author about MQTT, M2M and IoT
@dobermai
![Page 6: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/6.jpg)
• Macbook E-Mail Stockphoto
https://flic.kr/p/aERxbF
![Page 8: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/8.jpg)
![Page 10: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/10.jpg)
• Imagine Bild
![Page 11: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/11.jpg)
• Internet of Things
Internet of Things
![Page 12: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/12.jpg)
The Internet of Things (IoT) refers to uniquely identifiable objects and their virtual representations in an
Internet-like structure
![Page 13: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/13.jpg)
Why should
we care?
![Page 14: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/14.jpg)
Some statistics
2010 2015 2020
~6.909.000.000 ~7.302.000.000 ~7.675.000.000
~12.500.000.000 ~25.000.000.000 ~50.000.000.000
[1]Source: http://www.un.org/esa/population/publications/wpp2008/wpp2008_highlights.pdf
[1]
[2]Source: http://share.cisco.com/internet-of-things.html
[2]
![Page 15: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/15.jpg)
Some statistics
0
12,500,000,000
25,000,000,000
37,500,000,000
50,000,000,000
2010 2015 2020
People Things
![Page 16: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/16.jpg)
Some statistics
0
12,500,000,000
25,000,000,000
37,500,000,000
50,000,000,000
2010 2015 2020
People Things
1.8x
![Page 17: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/17.jpg)
Some statistics
0
12,500,000,000
25,000,000,000
37,500,000,000
50,000,000,000
2010 2015 2020
People Things
1.8x
3.4x
![Page 18: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/18.jpg)
Some statistics
0
12,500,000,000
25,000,000,000
37,500,000,000
50,000,000,000
2010 2015 2020
People Things
1.8x
3.4x
6.5x
![Page 19: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/19.jpg)
![Page 21: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/21.jpg)
![Page 23: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/23.jpg)
Evolution?
Revolution?
![Page 25: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/25.jpg)
TECHNOLOGY THAT SUPPORTS WIRED
OR WIRELESS COMMUNICATION BETWEEN DEVICES
![Page 26: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/26.jpg)
M2MInternet of Things
RFID
Bluetooth
Barcode
Non-IP
![Page 27: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/27.jpg)
Why now?
![Page 30: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/30.jpg)
Screenshot Taken from Oracle JavaOne Strategic Keynote 2013
![Page 32: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/32.jpg)
ChallengesSecurity Identity
ManagementInteroperability
PrivacyProvisioning
ScalabilityBIG Data
Device Management
...
![Page 33: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/33.jpg)
Protocols?
![Page 34: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/34.jpg)
Application Protocols
CoAP
HTTP
![Page 35: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/35.jpg)
‣ efficient in bandwidth
‣ scalable
‣ standardized
‣ open
‣ data agnostic
‣ must be suited for constrained devices AND server infrastructure
Requirements for an IoT Protocol
![Page 36: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/36.jpg)
Request / Response
Verbose
Polling instead of Push
No quality of service
How to get notified if clients die?
Stateless
HTTP?
![Page 37: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/37.jpg)
![Page 38: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/38.jpg)
What is MQTT‣ Messaging Protocol
‣ Simple
‣ On top of TCP
‣ Publish / Subscribe Architecture
‣ Binary protocol
‣ Minimal Overhead
‣ Designed for unreliable networks
‣ Data agnostic
![Page 39: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/39.jpg)
Use cases‣ Push instead of Poll
‣ Bandwidth is at a premium
‣ Enterprise applications should interact with mobile applications
‣ Reliable delivery of messages over unreliable networks
‣ Constrained devices
‣ Low latency
![Page 40: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/40.jpg)
Features‣ Topic Wildcards
‣ 3 Quality of Service Levels
‣ Retained Messages
‣ Last Will and Testament
‣ Persistent Sessions
‣ Heartbeats
![Page 41: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/41.jpg)
Publish / Subscribe
![Page 42: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/42.jpg)
Publish / Subscribe
![Page 43: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/43.jpg)
MQTT Topics
![Page 44: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/44.jpg)
‣ Hierarchical
‣ Very lightweight
‣ Subtopic-Level Wildcards (+)
‣ Subtree-Level Wildcards (#)
‣ Max 64.000 characters
‣ Clients can publish / subscribe to N topics
‣ Brokers can queue for topics if QoS > 0
MQTT Topics
![Page 45: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/45.jpg)
MQTT Topics
![Page 46: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/46.jpg)
MQTT Topicshouse1/floor1/kitchen/light
![Page 47: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/47.jpg)
MQTT Topicshouse1/floor1/kitchen/light
house1/floor1/kitchen/+
![Page 48: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/48.jpg)
MQTT Topicshouse1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
![Page 49: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/49.jpg)
MQTT Topicshouse1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
![Page 50: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/50.jpg)
MQTT Topicshouse1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
house1/#
![Page 51: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/51.jpg)
MQTT Topicshouse1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
house1/#
+/floor1/+/#
![Page 52: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/52.jpg)
MQTT Topicshouse1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
house1/#
+/floor1/+/#
+/+/+/#
![Page 53: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/53.jpg)
MQTT Topics
MQTT/is/awesome MQTT/is/fantastic
Bacon/is/awesome
MQTT/looks/fantasticBacon/looks/fantastic
![Page 54: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/54.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
![Page 55: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/55.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
![Page 56: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/56.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
![Page 57: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/57.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
![Page 58: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/58.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
![Page 59: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/59.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
![Page 60: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/60.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
![Page 61: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/61.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
![Page 62: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/62.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
![Page 63: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/63.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
![Page 64: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/64.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
![Page 65: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/65.jpg)
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
![Page 66: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/66.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 67: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/67.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 68: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/68.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 69: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/69.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 70: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/70.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 71: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/71.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 72: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/72.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
![Page 73: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/73.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 74: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/74.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 75: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/75.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 76: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/76.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 77: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/77.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 78: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/78.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 79: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/79.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 80: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/80.jpg)
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
![Page 81: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/81.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 82: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/82.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 83: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/83.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 84: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/84.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 85: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/85.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 86: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/86.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 87: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/87.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 88: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/88.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 89: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/89.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
![Page 90: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/90.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 91: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/91.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 92: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/92.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 93: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/93.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 94: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/94.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 95: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/95.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 96: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/96.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 97: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/97.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 98: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/98.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 99: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/99.jpg)
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
![Page 100: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/100.jpg)
Quality of Service Levels
QoS 0 At most once delivery
The message is delivered once or never.
QoS 1 At least once delivery
The message is delivered once or more.
QoS 2 Exactly once delivery
The message is delivered exactly once.
![Page 101: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/101.jpg)
Last Will and Testament‣ Clients can specify a LWT
‣ Broker publishes the LWT message on behalf of the client on “death”
‣ Useful for reporting problems
‣ Real push on device “death”
‣ Mostly used for reporting the connection status of a device
![Page 102: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/102.jpg)
Retained messages‣ Last known good value
‣ Last message is stored for a topic
‣ Publishing clients decide if the message should be retained
‣ Clients automatically receive the retained message after subscribing
![Page 103: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/103.jpg)
SecurityProtocol
‣ Username / Password
‣ Payload Encryption
Transport
‣ TLS
‣ Client certificate authentication
Broker
‣ Publish / Subscribe Permissions
‣ Integration to other systems (databases, APIs, ....)
![Page 104: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/104.jpg)
History
1999 2010 2013 2014
MQTT inventedby IBM and
Arcom (Eurotech)
royalty free OASIS TC formed
MQTT is OASIS standard
![Page 105: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/105.jpg)
Real world use cases
![Page 106: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/106.jpg)
Use case:
‣ more than 850M Facebook Messenger Users
‣ Chat application
‣ Improved Battery
‣ Lower latency
‣ Less bandwidth
https://www.facebook.com/notes/facebook-engineering/building-facebook-messenger/10150259350998920
Facebook Messenger
![Page 107: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/107.jpg)
Use case:
‣MQTT as central message “bus”
‣ Easy to integrate with other technologies
‣ Remote monitoring
‣ Many open source Smart Home Frameworks
support MQTT
‣ Remote control
Smart Home
![Page 108: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/108.jpg)
Use case:
‣30.000 devices
‣ 17.000 km pipeline
‣ Remote monitoring
‣ Remote control
‣ Uses satellite links
‣ Bandwidth is very expensive
Pipelines
![Page 109: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/109.jpg)
Gaining traction
Google Trends - 2014/05/13
![Page 110: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/110.jpg)
MQTT Brokers
![Page 111: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/111.jpg)
Mosquitto
‣ Open Source
‣ Ideal for running in constrained environments
‣ Supports Bridging
‣Written in C
![Page 112: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/112.jpg)
HiveMQ‣ High Performance
MQTT broker
‣ Native Websockets Support
‣ Java Plugin System
‣ Clustering
‣ Bridging
‣ Scalable to > 100.000 connections
![Page 113: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/113.jpg)
Other brokers
+ Many otherssee https://github.com/mqtt/mqtt.github.io/wiki/brokers
![Page 114: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/114.jpg)
Scaling
HIER SCALING BILD
![Page 115: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/115.jpg)
Bridging
![Page 116: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/116.jpg)
Clustering
![Page 117: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/117.jpg)
Broker comparisonQoS
0QoS
1QoS
2Auth Bridge $SYS SSL dynamic
topicscluster websockets plugins
HiveMQ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
mosquitto ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ X X ✔
RSMB ✔ ✔ ✔ ✔ ✔ ✔ X ✔ X X X
RabbitMQ ✔ ✔ X ✔ X X ✔ ✔ ? ? ?
ActiveMQ ✔ ✔ ✔ ? X X ? ? ? ✔ ?
![Page 118: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/118.jpg)
MQTT Clients
![Page 119: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/119.jpg)
Eclipse Paho‣ Open Source
‣ “Reference Implementation”
‣ Available in many languages: Java, Javascript, Lua, C, C++, Go, Python
‣ The JS library uses websockets
‣ Active Community
![Page 120: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/120.jpg)
MqttClient client = new MqttClient( "tcp://localhost:1883", //URI "publisher", //Client ID new MemoryPersistence()); //Persistence
client.connect();
client.publish("the/topic", //topic "message".getBytes(), //message 1, //QoS false); //retained
client.disconnect();
![Page 121: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/121.jpg)
MqttClient client = new MqttClient( "tcp://localhost:1883", //URI "publisher", //Client ID new MemoryPersistence()); //Persistence
MqttConnectOptions connOptions = new MqttConnectOptions();
connOptions.setKeepAliveInterval(120); connOptions.setWill("help/I/died",
new byte[0], 2, true); connOptions.setCleanSession(false); connOptions.setUserName("username"); connOptions.setPassword("passw".toCharArray());
client.connect(connOptions);
![Page 122: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/122.jpg)
MqttAsyncClient client = new MqttAsyncClient(...);
client.connect(null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { try { client.publish(...); } catch (MqttException e) {} }
@Override public void onFailure(IMqttToken asyncActionToken,
Throwable exception) {} }); client.disconnect();
![Page 123: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/123.jpg)
final MqttClient client = new MqttClient(...);
client.setCallback(new MqttCallback() { @Override public void connectionLost(Throwable cause) {}
@Override public void messageArrived(String topic,
MqttMessage message)throws Exception { System.out.println(new String(message.getPayload())); }
@Override public void deliveryComplete(IMqttDeliveryToken token) {} }); client.connect();
client.subscribe("#");
![Page 124: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/124.jpg)
Fusesource MQTT Client
‣ Java
‣ 3 API Styles
‣ Very easy to intercept
‣ Based on HawtIO
‣ Very performant
‣ In Maven Central
![Page 125: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/125.jpg)
MQTT mqtt = new MQTT(); mqtt.setHost("localhost", 1883); mqtt.setClientId("clientId"); mqtt.setCleanSession(false);
mqtt.setWillTopic("willtopic"); mqtt.setWillMessage("willmessage"); mqtt.setWillQos(QoS.EXACTLY_ONCE);
mqtt.setUserName("user"); mqtt.setPassword("passwd");
BlockingConnection conn = mqtt.blockingConnection();
conn.connect();
![Page 126: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/126.jpg)
MQTT mqtt = new MQTT(); BlockingConnection conn =
mqtt.blockingConnection(); conn.connect();
conn.publish("the/topic", //topic "message".getBytes(), //message QoS.EXACTLY_ONCE, //QoS false);
conn.disconnect();
![Page 127: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/127.jpg)
MQTT mqtt = new MQTT();
FutureConnection conn = mqtt.futureConnection(); Future<Void> connectFuture = conn.connect();
// funky business logic
connectFuture.await();
conn.publish("the/topic", //topic "message".getBytes(), //message QoS.EXACTLY_ONCE, //QoS false). then(new Callback<Void>() { @Override public void onSuccess(Void value) { System.out.println("Success"); }
@Override public void onFailure(Throwable value) {}});
![Page 128: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/128.jpg)
MQTT mqtt = new MQTT(); CallbackConnection conn = mqtt.callbackConnection(); conn.connect(new Callback<Void>() { @Override public void onSuccess(Void value) { conn.publish("the/topic", //topic "message".getBytes(), //message QoS.EXACTLY_ONCE, //QoS false, //retain new Callback<Void>() { @Override public void onSuccess(Void value) { System.out.println("Published"); }
@Override public void onFailure(Throwable value) {} }); } @Override public void onFailure(Throwable value) {}});
![Page 129: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/129.jpg)
Other MQTT Clients
https://github.com/mqtt/mqtt.github.io/wiki/libraries
![Page 130: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/130.jpg)
MQTT over Websockets
![Page 131: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/131.jpg)
‣ Every Browser is a ‘device’
‣ Device-to-Browser Push
‣ Broadcasting to all online users
‣ Detect if a user is offline
‣ Direct Browser-to-device push
‣ Minimum payload
‣ No application-specific protocol
MQTT over websockets
![Page 132: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/132.jpg)
![Page 133: JAX 2014 - M2M for Java Developers with MQTT](https://reader033.vdocuments.net/reader033/viewer/2022061104/54115c928d7f725c7f8b4578/html5/thumbnails/133.jpg)
Thanks!@dobermai