Slide 1

Slide 1 text

MQTT for sysadmins and for fun Jan-Piet Mens April 2014 @jpmens

Slide 2

Slide 2 text

@jpmens: consultant, author, architect, part-time admin, small-scale fiddler, loves LDAP, DNS, plain text, and things that work.

Slide 3

Slide 3 text

MQTT is a standard, a transport, PUB/SUB messaging, designed for unreliable networks

Slide 4

Slide 4 text

transport protocol binary payload, 256MB, (+2 bytes) , fast, lightweight, ideal for low- bandwith, high-latency networks

Slide 5

Slide 5 text

security TLS authentication ACLs TLS-PSK (payload encryption)

Slide 6

Slide 6 text

Quality of Service 0 At most once 1 Assured delivery 2 Once only

Slide 7

Slide 7 text

more features keepalive last will & testament

Slide 8

Slide 8 text

compare HTTP ? request/response, verbose, push, poll, nobody hears clients die

Slide 9

Slide 9 text

PUB/SUB decoupled senders recipients: flexibility one producer to many (changing) consumers no queueing broker can hold messages until subscriber reconnects durable (retain) Last Will and Testament single TCP port (easy on firewalls)

Slide 10

Slide 10 text

topic names UTF-8, hierarchical, wildcards temperature/room/living devices/# finance/+/eur/rate

Slide 11

Slide 11 text

PUB/SUB cauldron

Slide 12

Slide 12 text

MQTT brokers the server bit of MQTT

Slide 13

Slide 13 text

Mosquitto C, fast, lightweight, ACLs (plugin), TLS, TLS-PSK, bridge, logging via $SYS http://mosquitto.org

Slide 14

Slide 14 text

HiveMQ Java, plugins, Websockets, clustering, modules http://hivemq.com

Slide 15

Slide 15 text

more brokers RSMB, Mosca, Apollo, RabbitMQ

Slide 16

Slide 16 text

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.2 $SYS/broker/publish/messages/received 19798673 $SYS/broker/publish/messages/sent 30622855 $SYS/broker/publish/bytes/received 1868229299 $SYS/broker/publish/bytes/sent 3185942282

Slide 17

Slide 17 text

bridging

Slide 18

Slide 18 text

CLI utilities mosquitto_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] -m payload

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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 payload topic

Slide 21

Slide 21 text

Python API: SUB #!/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" % (msg.topic, str(msg.payload)) mqttc = paho.Client() mqttc.on_connect = on_connect mqttc.on_message = on_message mqttc.connect("localhost", 1883, 60) mqttc.loop_forever() callbacks

Slide 22

Slide 22 text

Python API: SUB $ mosquitto_pub -t 'conf/thirsty' -m 'Beertime?' $ mosquitto_pub -t 'conf/catering' -m 'Coffee is ready' $ ./sub.py conf/thirsty Beertime? conf/catering Coffee is ready

Slide 23

Slide 23 text

devices

Slide 24

Slide 24 text

devices

Slide 25

Slide 25 text

practical solutions alerting, metering, logging, location awareness, tracking, automation, and controlling

Slide 26

Slide 26 text

MQTT out there Github (notifications), power metering, trains, FaceBook messenger, connected cars, temperature monitoring, host monitoring (load)

Slide 27

Slide 27 text

system utilities Ansible (notifications), Fluentd (logging), Diamond (system metrics), mqtt-watchdir, Jenkins, (build logs),

Slide 28

Slide 28 text

database persistence SUB and store in any SQL or NoSQL database

Slide 29

Slide 29 text

alerting: mqttwarn https://github.com/jpmens/mqttwarn

Slide 30

Slide 30 text

job control, reporting https://gist.github.com/jpmens/7101170 $ mosquitto_sub -v -t 'processes/#' processes/run.sh Starting processes/run.sh Still running processes/monitor/spec1 Starting processes/run.sh Still going strong at Tue Oct 22 15:49:07 CEST 2013 processes/run.sh That's it, folks!

Slide 31

Slide 31 text

WebSockets HiveMQ, WSS, lighttpd mod_websocket

Slide 32

Slide 32 text

WebSockets http://www.hivemq.com/demos/websocket-client/

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Node-RED http://nodered.org

Slide 36

Slide 36 text

mqtt.org @mqttorg