osdc 2015: jan-piet mens | mqtt for your data center (and for the iot)

27
MQTT for your data center (and for the IoT) Jan-Piet Mens April 2015 @jpmens

Upload: netways

Post on 15-Jul-2015

113 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

MQTT for your data center (and for the IoT)

Jan-Piet MensApril 2015@jpmens

Page 2: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

MQTT is a standard, a transport,

PUB/SUB messaging, designed for

unreliable networks

Page 3: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

transport protocol

binary payload, 256MB, (+2 bytes), fast,

lightweight, ideal for low-bandwith, high-latency networks

Page 4: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

security

TLSauthentication

ACLsTLS-PSK

(payload encryption)

Page 5: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

Quality of Service

0 At most once

1 Assured delivery

2 Once only

Page 6: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

more featureskeepalive

last will & testament,decoupled senders/recipients,

durable messages

Page 7: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

topic names

UTF-8, hierarchical, wildcards

temperature/room/livingdevices/#finance/+/eur/rate

Page 8: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

PUB/SUB cauldron

Page 9: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

MQTT brokersthe server bit of MQTT

Page 10: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

Mosquitto C, fast, lightweight, ACLs (plugin), TLS, TLS-PSK, bridge,

Websockets, logging via $SYS

http://mosquitto.org

Page 11: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

HiveMQ Java, plugins, Websockets, clustering, modules

http://hivemq.com

Page 12: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

MQTT brokers$SYS topic

$SYS/broker/clients/total 1771$SYS/broker/messages/received 36597465$SYS/broker/messages/sent 39714120$SYS/broker/messages/stored 2941$SYS/broker/bytes/received 2830787008$SYS/broker/bytes/sent 3810653433$SYS/broker/version mosquitto version 1.4$SYS/broker/publish/messages/received 19798673$SYS/broker/publish/messages/sent 30622855$SYS/broker/publish/bytes/received 1868229299$SYS/broker/publish/bytes/sent 3185942282

Page 13: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

bridging

Page 14: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

CLI utilitiesmosquitto_sub -v [-h localhost] [-p 1883] [--cafile file] [--cert file --key file] [-u username [-P password]] [ --tls-version tlsv1.2 ] -t 'topic/#'

subscribe

publish

mosquitto_pub ... [-r] -t topic -m payload

Page 15: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

languages

Lua, Python, C, JavaScript, Perl, Ruby, Java, ...

Page 16: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

Python API: PUB#!/usr/bin/env python

import paho.mqtt.publish as mqtt

mqtt.single('conf/hello', 'Hello MQTT')

$ mosquitto_sub -h localhost -v -t 'conf/#'conf/hello Hello MQTT

payloadtopic

Page 17: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

Python API: SUB

callbacks

#!/usr/bin/env python

import paho.mqtt.client as paho

def on_connect(mosq, userdata, rc): mqttc.subscribe("conf/+", 0)

def on_message(mosq, userdata, msg): print "%s %s %s" % (msg.topic, str(msg.payload), userdata)

data = { 'type' : 'conference' }mqttc = paho.Client(userdata=data)mqttc.on_connect = on_connectmqttc.on_message = on_message

mqttc.connect("localhost", 1883, 60)mqttc.loop_forever()

Page 18: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

Python API: SUB

$ mosquitto_pub -t 'conf/thirsty' -m 'Beertime?'$ mosquitto_pub -t 'conf/catering' -m 'Coffee is ready'

$ ./sub.pyconf/thirsty Beertime? {'type': 'conference'}conf/catering Coffee is ready {'type': 'conference'}

Page 19: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

practical solutions

alerting, metering, logging, location awareness, tracking, automation, and controlling, host monitoring

Page 20: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

alerting: mqttwarn

https://github.com/jpmens/mqttwarn

Page 21: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

temperature: Arduino

huh?

Page 22: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

all good!

Page 23: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

how does this work?

arduino/10.0.69.105/celsius 24

Page 24: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

critical: not good!

Page 25: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

via MQTT to mobile

Page 26: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

MQTT in the wild

Graylog, beaver, Ansible, RabbitMQ, collectd, openHAB, Github, Wireshark, Flukso, RemakeElectric, Jenkins, Diamond,

Page 27: OSDC 2015: Jan-Piet Mens | MQTT for your data center (and for the IoT)

mqtt.org @mqttorg