Dominik Obermaier | dc-square GmbH
M2M for Java Developers with MQTT
About me
Hi, I’m Dominik Obermaier.
• CTO of dc-square
• HiveMQ architect
• helped standardizing MQTT at OASIS
• Speaker a...
• Typical morning
https://flic.kr/p/eaX1GC
https://flic.kr/p/7Vvzvp
https://flic.kr/p/48VxKfhttps://flic.kr/p/hLd8CU
• Macbook E-Mail Stockphoto
https://flic.kr/p/aERxbF
• Dusche Stockphoto
https://flic.kr/p/6JuGDb
https://flic.kr/p/3QYv2o
• Imagine Bild
• Internet of Things
Internet of Things
The Internet of Things (IoT) refers to
uniquely identifiable objects and
their virtual representations in an
Internet-like...
Why
should
we
care?
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.00...
Some statistics
0
12,500,000,000
25,000,000,000
37,500,000,000
50,000,000,000
2010 2015 2020
People Things
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
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
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
https://flic.kr/p/athSFb
• Android Photo
https://flic.kr/p/9vSR9i
Evolution?
Revolution?
M2M?
https://flic.kr/p/834e93
TECHNOLOGY THAT
SUPPORTS WIRED
OR WIRELESS
COMMUNICATION
BETWEEN DEVICES
M2MInternet of Things
RFID
Bluetooth
Barcode
Non-IP
Why now?
https://flic.kr/p/8EidjG
https://flic.kr/p/daTVZY
Screenshot Taken from Oracle JavaOne Strategic Keynote 2013
Are we there yet?
https://flic.kr/p/5WR2fd
Challenges
Security Identity
Management
Interoperability
Privacy
Provisioning
Scalability
BIG Data
Device Management
...
Protocols?
Application Protocols
CoAP
HTTP
‣ efficient in bandwidth
‣ scalable
‣ standardized
‣ open
‣ data agnostic
‣ must be suited for constrained
devices AND ser...
Request / Response
Verbose
Polling instead of Push
No quality of service
How to get notified if clients die?
Stateless
HTT...
What is MQTT
‣ Messaging Protocol
‣ Simple
‣ On top of TCP
‣ Publish / Subscribe
Architecture
‣ Binary protocol
‣ Minimal ...
Use cases
‣ Push instead of Poll
‣ Bandwidth is at a premium
‣ Enterprise applications
should interact with
mobile applica...
Features
‣ Topic Wildcards
‣ 3 Quality of Service
Levels
‣ Retained Messages
‣ Last Will and
Testament
‣ Persistent Sessio...
Publish / Subscribe
Publish / Subscribe
MQTT Topics
‣ Hierarchical
‣ Very lightweight
‣ Subtopic-Level Wildcards (+)
‣ Subtree-Level Wildcards (#)
‣ Max 64.000 characters
‣ C...
MQTT Topics
MQTT Topics
house1/floor1/kitchen/light
MQTT Topics
house1/floor1/kitchen/light
house1/floor1/kitchen/+
MQTT Topics
house1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
MQTT Topics
house1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
MQTT Topics
house1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
house1/#
MQTT Topics
house1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
house1/#
+/floor1/+...
MQTT Topics
house1/floor1/kitchen/light
house1/floor1/kitchen/+
house1/floor1/+/light
house1/+/+/light
house1/#
+/floor1/+...
MQTT Topics
MQTT/is/awesome MQTT/is/fantastic
Bacon/is/awesome
MQTT/looks/fantasticBacon/looks/fantastic
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
MQTT/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
MQTT Topics
MQTT Bacon
is
awesome
looks
fantastic
Bacon/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/awesome
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Topic Level Wildcard
MQTT Bacon
is
awesome
looks
fantastic
+/is/+
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
MQTT/#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
MQTT Subtree Wildcard
MQTT Bacon
is
awesome
looks
fantastic
#
Quality of Service Levels
QoS 0
At most once delivery
The message is delivered once or never.
QoS 1
At least once delivery...
Last Will and Testament
‣ Clients can specify a LWT
‣ Broker publishes the LWT
message on behalf of the
client on “death”
...
Retained messages
‣ Last known good value
‣ Last message is stored
for a topic
‣ Publishing clients
decide if the message
...
Security
Protocol
‣ Username / Password
‣ Payload Encryption
Transport
‣ TLS
‣ Client certificate
authentication
Broker
‣ ...
History
1999 2010 2013 2014
MQTT invented
by IBM and
Arcom
(Eurotech)
royalty free OASIS TC
formed
MQTT is
OASIS
standard
Real world
use cases
Use case:
‣ more than 850M Facebook Messenger Users
‣ Chat application
‣ Improved Battery
‣ Lower latency
‣ Less bandwidth...
Use case:
‣MQTT as central message “bus”
‣ Easy to integrate with other technologies
‣ Remote monitoring
‣ Many open sourc...
Use case:
‣30.000 devices
‣ 17.000 km pipeline
‣ Remote monitoring
‣ Remote control
‣ Uses satellite links
‣ Bandwidth is ...
Gaining traction
Google Trends - 2014/05/13
MQTT Brokers
Mosquitto
‣ Open Source
‣ Ideal for running
in constrained
environments
‣ Supports
Bridging
‣ Written in C
HiveMQ
‣ High Performance
MQTT broker
‣ Native Websockets
Support
‣ Java Plugin System
‣ Clustering
‣ Bridging
‣ Scalable ...
Other brokers
+ Many others
see https://github.com/mqtt/mqtt.github.io/wiki/brokers
Scaling
HIER SCALING BILD
Bridging
Clustering
Broker comparison
QoS
0
QoS
1
QoS
2
Auth Bridge $SYS SSL
dynamic
topics
cluster websockets plugins
HiveMQ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ...
MQTT Clients
Eclipse Paho
‣ Open Source
‣ “Reference
Implementation”
‣ Available in many
languages: Java,
Javascript, Lua, C, C++,
Go, ...
MqttClient client = new MqttClient(
"tcp://localhost:1883", //URI
"publisher", //Client ID
new MemoryPersistence()); //Per...
MqttClient client = new MqttClient(
"tcp://localhost:1883", //URI
"publisher", //Client ID
new MemoryPersistence()); //Per...
MqttAsyncClient client = new MqttAsyncClient(...);
client.connect(null, new IMqttActionListener() {
@Override
public void ...
final MqttClient client = new MqttClient(...);
client.setCallback(new MqttCallback() {
@Override
public void connectionLos...
Fusesource MQTT Client
‣ Java
‣ 3 API Styles
‣ Very easy to
intercept
‣ Based on HawtIO
‣ Very performant
‣ In Maven Centr...
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("clientId");
mqtt.setCleanSession(false);
mqtt.s...
MQTT mqtt = new MQTT();
BlockingConnection conn =
mqtt.blockingConnection();
conn.connect();
conn.publish("the/topic", //t...
MQTT mqtt = new MQTT();
FutureConnection conn = mqtt.futureConnection();
Future<Void> connectFuture = conn.connect();
// f...
MQTT mqtt = new MQTT();
CallbackConnection conn = mqtt.callbackConnection();
conn.connect(new Callback<Void>() {
@Override...
Other MQTT Clients
https://github.com/mqtt/mqtt.github.io/wiki/libraries
MQTT over Websockets
‣ Every Browser is a ‘device’
‣ Device-to-Browser Push
‣ Broadcasting to all online users
‣ Detect if a user is offline
‣ ...
Thanks!
@dobermai
JAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTT
Upcoming SlideShare
Loading in...5
×

JAX 2014 - M2M for Java Developers with MQTT

4,202

Published on

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.

Published in: Technology, Education
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,202
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
168
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide

Transcript of "JAX 2014 - M2M for Java Developers with MQTT"

  1. 1. Dominik Obermaier | dc-square GmbH M2M for Java Developers with MQTT
  2. 2. About me Hi, I’m Dominik Obermaier. • CTO of dc-square • HiveMQ architect • helped standardizing MQTT at OASIS • Speaker and author about MQTT, M2M and IoT @dobermai
  3. 3. • Typical morning https://flic.kr/p/eaX1GC
  4. 4. https://flic.kr/p/7Vvzvp
  5. 5. https://flic.kr/p/48VxKfhttps://flic.kr/p/hLd8CU
  6. 6. • Macbook E-Mail Stockphoto https://flic.kr/p/aERxbF
  7. 7. • Dusche Stockphoto https://flic.kr/p/6JuGDb
  8. 8. https://flic.kr/p/3QYv2o
  9. 9. • Imagine Bild
  10. 10. • Internet of Things Internet of Things
  11. 11. The Internet of Things (IoT) refers to uniquely identifiable objects and their virtual representations in an Internet-like structure
  12. 12. Why should we care?
  13. 13. 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]
  14. 14. Some statistics 0 12,500,000,000 25,000,000,000 37,500,000,000 50,000,000,000 2010 2015 2020 People Things
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. https://flic.kr/p/athSFb
  19. 19. • Android Photo https://flic.kr/p/9vSR9i
  20. 20. Evolution? Revolution?
  21. 21. M2M? https://flic.kr/p/834e93
  22. 22. TECHNOLOGY THAT SUPPORTS WIRED OR WIRELESS COMMUNICATION BETWEEN DEVICES
  23. 23. M2MInternet of Things RFID Bluetooth Barcode Non-IP
  24. 24. Why now?
  25. 25. https://flic.kr/p/8EidjG
  26. 26. https://flic.kr/p/daTVZY
  27. 27. Screenshot Taken from Oracle JavaOne Strategic Keynote 2013
  28. 28. Are we there yet? https://flic.kr/p/5WR2fd
  29. 29. Challenges Security Identity Management Interoperability Privacy Provisioning Scalability BIG Data Device Management ...
  30. 30. Protocols?
  31. 31. Application Protocols CoAP HTTP
  32. 32. ‣ efficient in bandwidth ‣ scalable ‣ standardized ‣ open ‣ data agnostic ‣ must be suited for constrained devices AND server infrastructure Requirements for an IoT Protocol
  33. 33. Request / Response Verbose Polling instead of Push No quality of service How to get notified if clients die? Stateless HTTP?
  34. 34. What is MQTT ‣ Messaging Protocol ‣ Simple ‣ On top of TCP ‣ Publish / Subscribe Architecture ‣ Binary protocol ‣ Minimal Overhead ‣ Designed for unreliable networks ‣ Data agnostic
  35. 35. 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
  36. 36. Features ‣ Topic Wildcards ‣ 3 Quality of Service Levels ‣ Retained Messages ‣ Last Will and Testament ‣ Persistent Sessions ‣ Heartbeats
  37. 37. Publish / Subscribe
  38. 38. Publish / Subscribe
  39. 39. MQTT Topics
  40. 40. ‣ 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
  41. 41. MQTT Topics
  42. 42. MQTT Topics house1/floor1/kitchen/light
  43. 43. MQTT Topics house1/floor1/kitchen/light house1/floor1/kitchen/+
  44. 44. MQTT Topics house1/floor1/kitchen/light house1/floor1/kitchen/+ house1/floor1/+/light
  45. 45. MQTT Topics house1/floor1/kitchen/light house1/floor1/kitchen/+ house1/floor1/+/light house1/+/+/light
  46. 46. MQTT Topics house1/floor1/kitchen/light house1/floor1/kitchen/+ house1/floor1/+/light house1/+/+/light house1/#
  47. 47. MQTT Topics house1/floor1/kitchen/light house1/floor1/kitchen/+ house1/floor1/+/light house1/+/+/light house1/# +/floor1/+/#
  48. 48. MQTT Topics house1/floor1/kitchen/light house1/floor1/kitchen/+ house1/floor1/+/light house1/+/+/light house1/# +/floor1/+/# +/+/+/#
  49. 49. MQTT Topics MQTT/is/awesome MQTT/is/fantastic Bacon/is/awesome MQTT/looks/fantasticBacon/looks/fantastic
  50. 50. MQTT Topics MQTT Bacon is awesome looks fantastic MQTT/is/awesome
  51. 51. MQTT Topics MQTT Bacon is awesome looks fantastic MQTT/is/awesome
  52. 52. MQTT Topics MQTT Bacon is awesome looks fantastic MQTT/is/awesome
  53. 53. MQTT Topics MQTT Bacon is awesome looks fantastic MQTT/is/awesome
  54. 54. MQTT Topics MQTT Bacon is awesome looks fantastic MQTT/is/awesome
  55. 55. MQTT Topics MQTT Bacon is awesome looks fantastic MQTT/is/awesome
  56. 56. MQTT Topics MQTT Bacon is awesome looks fantastic Bacon/is/awesome
  57. 57. MQTT Topics MQTT Bacon is awesome looks fantastic Bacon/is/awesome
  58. 58. MQTT Topics MQTT Bacon is awesome looks fantastic Bacon/is/awesome
  59. 59. MQTT Topics MQTT Bacon is awesome looks fantastic Bacon/is/awesome
  60. 60. MQTT Topics MQTT Bacon is awesome looks fantastic Bacon/is/awesome
  61. 61. MQTT Topics MQTT Bacon is awesome looks fantastic Bacon/is/awesome
  62. 62. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  63. 63. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  64. 64. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  65. 65. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  66. 66. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  67. 67. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  68. 68. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/awesome
  69. 69. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  70. 70. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  71. 71. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  72. 72. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  73. 73. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  74. 74. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  75. 75. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  76. 76. MQTT Topic Level Wildcard MQTT Bacon is awesome looks fantastic +/is/+
  77. 77. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  78. 78. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  79. 79. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  80. 80. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  81. 81. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  82. 82. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  83. 83. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  84. 84. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  85. 85. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic MQTT/#
  86. 86. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  87. 87. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  88. 88. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  89. 89. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  90. 90. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  91. 91. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  92. 92. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  93. 93. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  94. 94. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  95. 95. MQTT Subtree Wildcard MQTT Bacon is awesome looks fantastic #
  96. 96. 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.
  97. 97. 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
  98. 98. 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
  99. 99. Security Protocol ‣ Username / Password ‣ Payload Encryption Transport ‣ TLS ‣ Client certificate authentication Broker ‣ Publish / Subscribe Permissions ‣ Integration to other systems (databases, APIs, ....)
  100. 100. History 1999 2010 2013 2014 MQTT invented by IBM and Arcom (Eurotech) royalty free OASIS TC formed MQTT is OASIS standard
  101. 101. Real world use cases
  102. 102. 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
  103. 103. 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
  104. 104. Use case: ‣30.000 devices ‣ 17.000 km pipeline ‣ Remote monitoring ‣ Remote control ‣ Uses satellite links ‣ Bandwidth is very expensive Pipelines
  105. 105. Gaining traction Google Trends - 2014/05/13
  106. 106. MQTT Brokers
  107. 107. Mosquitto ‣ Open Source ‣ Ideal for running in constrained environments ‣ Supports Bridging ‣ Written in C
  108. 108. HiveMQ ‣ High Performance MQTT broker ‣ Native Websockets Support ‣ Java Plugin System ‣ Clustering ‣ Bridging ‣ Scalable to > 100.000 connections
  109. 109. Other brokers + Many others see https://github.com/mqtt/mqtt.github.io/wiki/brokers
  110. 110. Scaling HIER SCALING BILD
  111. 111. Bridging
  112. 112. Clustering
  113. 113. Broker comparison QoS 0 QoS 1 QoS 2 Auth Bridge $SYS SSL dynamic topics cluster websockets plugins HiveMQ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ mosquitto ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ X X ✔ RSMB ✔ ✔ ✔ ✔ ✔ ✔ X ✔ X X X RabbitMQ ✔ ✔ X ✔ X X ✔ ✔ ? ? ? ActiveMQ ✔ ✔ ✔ ? X X ? ? ? ✔ ?
  114. 114. MQTT Clients
  115. 115. Eclipse Paho ‣ Open Source ‣ “Reference Implementation” ‣ Available in many languages: Java, Javascript, Lua, C, C++, Go, Python ‣ The JS library uses websockets ‣ Active Community
  116. 116. 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();
  117. 117. 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);
  118. 118. 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();
  119. 119. 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("#");
  120. 120. Fusesource MQTT Client ‣ Java ‣ 3 API Styles ‣ Very easy to intercept ‣ Based on HawtIO ‣ Very performant ‣ In Maven Central
  121. 121. 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();
  122. 122. 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();
  123. 123. 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) {}});
  124. 124. 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) {}});
  125. 125. Other MQTT Clients https://github.com/mqtt/mqtt.github.io/wiki/libraries
  126. 126. MQTT over Websockets
  127. 127. ‣ 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
  128. 128. Thanks! @dobermai
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×