Top Banner
Messaging for IoT October 2015 Martyn Taylor, Dejan Bosanac
57

Messaging for IoT

Apr 14, 2017

Download

Software

dejanb
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Messaging for IoT

Messaging for IoT October 2015

Martyn  Taylor,  Dejan  Bosanac

Page 2: Messaging for IoT

Presenters

Martyn  Taylor •  Senior  So4ware  Engineer  at  Red  Hat •  Apache  Ac>veMQ  CommiCer

•  Mainly  working  on  Apache  Artemis •  Keen  interest  in  IoT Bosanac  Dejan •  Senior  So4ware  Engineer  at  Red  Hat •  Apache  Ac>veMQ  commiCer  and  PMC  member •  Co-­‐author  of  Ac>veMQ  in  Ac>on

Page 3: Messaging for IoT

Agenda

•  IoT  messaging  basics •  Tasks  and  challenges •  PaCerns  and  protocols

•  IoT  messaging  brokers •  Apache  Ac>veMQ •  Ac>veMQ  Artemis

•  IoT  messaging  scaling •  Ver>cal  and  horizontal •  Qpid  Dispatch  Router •  Scalable  deployments

Page 4: Messaging for IoT

IoT Messaging Basics

•  IoT  Topology •  Messaging  tasks •  Messaging  challenges

Page 5: Messaging for IoT

IoT Topology

 Big  Data

Messaging  Infrastructure

Analy>cs

Enterprise  Middleware

Devices

Page 6: Messaging for IoT

IoT Messaging Infrastructure

Task •  Provides  connec>vity  between  devices  and  backend  systems Challenges •  Interoperability •  Deployment  environment •  High  Availability •  Scalability

Page 7: Messaging for IoT

IoT connectivity patterns

•  IoT  Communica>on  PaCerns

•  Telemetry,  Command  &  Control,  Enquiry,  No>fica>ons •  Protocols  and  Technologies

•  JMS •  MQTT •  AMQP

Page 8: Messaging for IoT

Telemetry

•  Device  →  Service •  One  way  (push) •  Failures  tolerable •  Lots  of  small  data

Page 9: Messaging for IoT

Command  and  Control

•  Service  →  Device •  Two  way  (Req/Resp) •  Less,  more  important  data •  1  →  1  and  1  →  many  

•  grouping  

Page 10: Messaging for IoT

Enquiry

•  Device  →  Service •  1  →  1 •  Two  way  (Req/Resp)

Page 11: Messaging for IoT

No>fica>on

•  Service  →  Device •  One  Way  (push) •  1  →  Many

•  Grouping

Page 12: Messaging for IoT

Requirements  on  the  transport

•  Communica>on  from/to  devices •  1  →  1

•  Device  Addressing •  1  →  Many

•  Group  Addressing •  Push •  Request  →  Response

Page 13: Messaging for IoT

IoT  Networks

•  Unreliable •  Handle  network  failures

•  Expensive  and  Constrained •  Low  network  overhead

Page 14: Messaging for IoT

IoT  Devices

•  Limited  Resources •  Low  processing  overhead

•  Large  scale  and  varied •  Inter-­‐operable

•  BaCery  powered •  Work  offline

Page 15: Messaging for IoT

IoT  Environment  Challenges

•  Interoperable •  Connec>on  Failure  Handling •  Offline •  Low  network  overhead •  Low  Processing  overhead

Page 16: Messaging for IoT

JMS

•  Addresses  majority  of  requirements •  1-­‐1,  1-­‐Many,Grouping,Device  address

•  Queues,  Topics,  Message  Selectors •  Push •  Req/Resp

•  Reply  to  queues •  Inter-­‐operable

•  JVM •  Connec>on  failures

•  Durable  Messages  and  Various  ACK  Modes

Page 17: Messaging for IoT

JMS

•  Inter-­‐operability •  Java  Run>me  only •  Protocol  vs  API

•  Vendor  specific •  Rich  feature  set

•  Complexity  on  the  client •  Large  footprint

•  Vendor  protocols •  High  network  overhead

Page 18: Messaging for IoT

MQTT

•  OASIS  standard  (v3.1.1) •  Created  by  IBM

•  Light  weight •  Low  network  message •  Simple  protocol

•  Pub  /  Sub

•  Quality  of  Service

•  Connec>on  failures

•  Very  popular  in  IoT  scenarios

Page 19: Messaging for IoT

QoS  Levels

Page 20: Messaging for IoT

Overheads

•  Sending  /  Receiving  messages •  QoS  0  =  8  bytes •  QoS  1  =  min  12  bytes •  QoS  2  =  min  20  bytes

•  Clients  have  small  code  foot  print •  Simple  protocol •  Burden  on  the  broker

Page 21: Messaging for IoT

Failures

Page 22: Messaging for IoT

Reconnects

Page 23: Messaging for IoT

Subscrip>ons

•  Topics •  Hierarchical  addresses

•  e.g.  building/core/floor/2/office/1 •  Supports  wild  cards

•  building/core/floor/# •  building/core/floor/+/toilet/+

•  QoS  per  topic •  Outlives  a  connec>on

Page 24: Messaging for IoT

AMQP  1.0

•  Interna>onal  Standard  (ISO/IEC  ISO  19464) •  Binary  Protocol •  Rich  feature  set:

•  conversa>on  mul>plexing •  advanced  flow  control •  Type  system •  QoS  Guarantees

•  Symmetrical  message  exchange •  No  Broker  required

Page 25: Messaging for IoT

QoS  Guarantees

   Quality  of  Service  guarantees •  At  most  once

•  Fire  and  Forget •  At  least  once

•  Retry •  Exactly  once

•  3  Way  Ack

Page 26: Messaging for IoT

Type  System

•  Highly  Interoperable •  Rich  Type  Set

•  Primi>ves •  integer,  long •  lists,  maps

•  Descrip>ve  types •  Allow  applica>on  defined  types

•  Mappings  in  most  languages

Page 27: Messaging for IoT

Symmetrical  Protocol

•  Client  -­‐>  Broker •  Broker  less  message

•  Client  -­‐>  Client •  Client  -­‐>  Router

•  Interes>ng  features •  Smart  rou>ng

Page 28: Messaging for IoT

Flow  control  and  Mul>  Channels

•  Limit  producer  and  consumer  flow •  Each  channel  (link)  can  be  controlled  individually •  Limit  telemetry  flow  for  command  messages

Page 29: Messaging for IoT

Protocols  Overview

•  Lots  of  IoT  protocol  choices  including  several  not  discussed  here •  The  right  choice  depends  of  the  scenario •  Scenarios  may  combine  protocols

CoAP

Target  usecase Long-­‐haul  (&  local)

Long-­‐haul Local  (&  long-­‐haul)

Long-­‐haul

Compactness High Medium Highest Verbose Security SSL SSL DTLS SSL Flow  control No Yes No No Structured  message

No Yes No Yes

Complexity Medium High Low Lowest

Page 30: Messaging for IoT

IoT Messaging Brokers

•  Apache  Ac>veMQ •  Ac>veMQ  Artemis

Page 31: Messaging for IoT

Apache ActiveMQ

•  Apache  Ac>veMQ  is  a  high-­‐performance,  scalable  messaging  broker •  Started  as  an  open  source  JMS  broker •  Moved  to  Apache  So4ware  Founda>on  in  2006 •  Now  widely  used  open  source  messaging  system

Page 32: Messaging for IoT

Apache ActiveMQ

•  Mul>-­‐Protocol/Mul>-­‐Language  Support •  Invented  Stomp  protocol  in  2006 •  Now  supports  AMQP  1.0,  MQTT  3.1.1,  HTTP,  STOMP  protocols •  Broad  range  of  supported  client  libraries  for  all  kinds  of  device  

hardware

Page 33: Messaging for IoT

Apache ActiveMQ

•  Benefits

•  Feature  rich •  BaCle-­‐tested  in  many  produc>on  environments •  Good  security  support •  Flexible •  Configurable •  Embeddable

Page 34: Messaging for IoT

Apache ActiveMQ

•  Limita>ons

•  Broker  core  gepng  old •  WriCen  using  synchronous  thread-­‐locking  model •  It  limits  ver>cal  scalability  of  the  broker •  Number  of  threads  raise  with  number  of  connec>ons  and  des>na>ons

Page 35: Messaging for IoT

Ac>veMQ  Artemis

•  Mul>  Protocol  Broker

•  AMQP,  MQTT,  STOMP,  OpenWire,  Artemis  Core •  JMS  (API)

•  Started  as  HornetQ  JBoss  project  in  2009 •  Embedded  WildFly  (JBoss  AS)  JMS  messaging  service •  In  2014  donated  to  Apache  Ac>veMQ

•  Sub  project  Ac>veMQ  Artemis. •  Latest  Release  1.1.0

Page 36: Messaging for IoT

Ac>veMQ  Artemis:  Core

•  Contains  Broker  Business  logic •  Core  maintains  a  >ght  scope

•  Message  Rou>ng •  Persistence •  Protocol  u>lity  API •  HA  and  Scaling

•  Highly  Performance •  Protocols  are  plugged  in

Page 37: Messaging for IoT

Ac>veMQ  Artemis:  Architecture

Artemis Core

Page 38: Messaging for IoT

Apache  Artemis  Summary

•  Great  performance  due  to •  Reac>ve  Architecture •  Efficient  Append  only  Journal

•  Mul>  -­‐  Protocol  Broker •  AMQP,  MQTT,  STOMP,  CORE,  OpenWire •  JMS

•  HA  and  Scalability  built  in

Page 39: Messaging for IoT

Apache  Artemis  Next  Steps

•  Take  features  from  Ac>veMQ

•  Enhance  OpenWire  support  for  Ac>veMQ  compa>bility

•  JDBC  Journal  implementa>on

•  More  protocols •  CoAP •  Your  protocol  here….

Page 40: Messaging for IoT

IoT Messaging Scaling

•  Ver>cal  and  Horizontal  scaling  of  Brokers •  Qpid  Dispatch  Router •  Scalable  Deployment

Page 41: Messaging for IoT

Broker – Vertical Scaling

•  Give  broker  enough  resources •  Reduce  thread  usage

•  NIO  transport •  Reac>ve  architecture

•  Improve  monitoring  under  stress •  Advisory  messages •  Selec>ve  Mbean  registra>on

Page 42: Messaging for IoT

Broker – Horizontal Scaling

•  One  broker  can  only  do  so  much •  Horizontal  scaling  by  using  networks  of  brokers

•  Load  balance  connec>ons •  Limita>ons

•  All  des>na>ons  on  all  brokers •  Broker  network  is  the  boCleneck

Page 43: Messaging for IoT

Qpid Dispatch Router

•  Lightweight  AMQP  1.0  message  router  wriCen  in  C •  hCp://qpid.apache.org/components/dispatch-­‐router/   •  Provides  flexible  and  scalable  interconnect  between  AMQP  

endpoints

Page 44: Messaging for IoT

Qpid Dispatch Router

•  It  is  not  a  broker •  It  never  owns  a  message   •  It  propagates  AMQP  transfer,  seClement  and  disposi>on  frames  

between  endpoints •  Message  based  or  link  based  rou>ng

Router

/device1

/device2

Page 45: Messaging for IoT

Qpid Dispatch Router

•  It  can  be  deployed  in  mul>ple  router-­‐broker-­‐endpoint  topology •  Redundant  paths

Router

Broker

Router

Page 46: Messaging for IoT

Qpid Dispatch Router

•  Cost-­‐based  route  computa>on

Router

Broker

Router

Page 47: Messaging for IoT

Qpid Dispatch Router

•  Automa>c  re-­‐rou>ng  on  failure

Router

Broker

Router

Page 48: Messaging for IoT

Qpid dispatch router

•  Benefits

•  BeCer  scaling  due  to  more  focused  tasks •  Smart  rou>ng  can  be  used  to  par>>on  the  traffic •  Ideal  candidate  for  gateway  into  the  system

Page 49: Messaging for IoT

Scalable deployments

•  Combina>on  of  brokers  and  routers  provides  powerful  tool  box •  Brokers  should  focus  on  storing  messages •  Routers  should  do  the  rest •  Allows  for  horizontal  scaling  topologies  that  can  solve  IoT  

challenges

Page 50: Messaging for IoT

Scalable deployments

•  Smarter  scaling  techniques  using  routers

•  Connec>ons  concentra>on •  Des>na>ons  concentra>on •  Des>na>on  sharding •  Smart  rou>ng

Page 51: Messaging for IoT

Connection Concentration

Router

Broker

•  Challenge:    Reduce  the  number  of  connec>ons  on  the  broker

Page 52: Messaging for IoT

Destination Concentration

Router

Broker

/building1/room1

/building1

/building1/room2

/building1/room2

•  Challenge:    Reduce  the  number  of  des>na>ons  on  the  broker

Page 53: Messaging for IoT

Destination Sharding

Router

Broker

Queue.A

Broker

Queue.B

•  Challenge:    Distribute  des>na>ons  across  brokers

Page 54: Messaging for IoT

Deployments – Smart Routing

Router

Broker

QoS  0

•  Challenge:    Decrease  the  load  of  messages  on  the  broker

Page 55: Messaging for IoT

Deployments – Smart Routing

Router

Broker

QoS  1

Page 56: Messaging for IoT

Summary

•  IoT  offers  a  new  set  of  problems  for  communica>on •  Messaging  is  a  good  fit •  We  need  new  tools  and  technologies  to  help

•  Protocols  such  as  AMQP  and  MQTT  help  address  some  of  these  problems

•  Ac>veMQ  and  Artemis  are  evolving  to  meet  IoT  demands •  New  tools  such  as  Apache  Dispatch  Router  allow  us  to  do  some  

novel  things  to  help  scale  to  really  high  numbers

Page 57: Messaging for IoT

Resources

•  Slides •  hCp://hCp://www.slideshare.net/dejanb/messaging-­‐for-­‐iot    

•  MQTT •  Spec:  hCp://www.mqC.org   •  Libraries  and  tutorials:  hCp://www.eclipse.org/paho/  

•  AMQP •  Spec:  hCp://www.amqp.org/   •  Libraries  and  tutorials:  hCp://qpid.apache.org/  

•  Ac>veMQ  and  Artemis •  hCp://ac>vemq.apache.org/  

•  Dispatch  Router •  hCp://qpid.apache.org/components/dispatch-­‐router/