Top Banner
ibm.com/redbooks IBM ® WebSphere ® Front cover Building Smarter Planet Solutions with MQTT and IBM WebSphere MQ Telemetry Valerie Lampkin Weng Tat Leong Leonardo Olivera Sweta Rawat Nagesh Subrahmanyam Rong Xiang Introduces MQTT and includes scenarios that demonstrate its capabilities Provides a quick guide to getting started with MQTT Includes typical usage patterns and guidance on scaling a solution
270

Building Smarter Planet Solutions with MQTT and IBM ... · PDF fileibm.com/redbooks IBM ® WebSphere ® Front cover Building Smarter Planet Solutions with MQTT and IBM WebSphere MQ

Mar 09, 2018

Download

Documents

vutu
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
  • ibm.com/redbooks

    IBM WebSphere Front cover

    Building Smarter Planet Solutions with MQTT and IBM WebSphere MQ Telemetry

    Valerie LampkinWeng Tat Leong

    Leonardo OliveraSweta Rawat

    Nagesh SubrahmanyamRong Xiang

    Introduces MQTT and includes scenarios that demonstrate its capabilities

    Provides a quick guide to getting started with MQTT

    Includes typical usage patterns and guidance on scaling a solution

    http://www.redbooks.ibm.com/ http://www.redbooks.ibm.com/

  • International Technical Support Organization

    Building Smarter Planet Solutions with MQTT and IBM WebSphere MQ Telemetry

    September 2012

    SG24-8054-00

  • Copyright International Business Machines Corporation 2012. All rights reserved.Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP ScheduleContract with IBM Corp.

    First Edition (September 2012)

    This edition applies to Version 7, Release 1 of WebSphere MQ.

    Note: Before using this information and the product it supports, read the information in Notices on page vii.

  • Contents

    Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viiTrademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii

    Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ixThe team who wrote this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

    Primary authors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ixAdditional authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xAdditional contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

    Now you can become a published author, too! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiComments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiiStay connected to IBM Redbooks publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii

    Chapter 1. Overview of MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1 Building a Smarter Planet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    1.1.1 Internet of Things . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.2 Smarter Planet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.1.3 Telemetry and the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    1.2 MQTT and WebSphere MQ Telemetry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2.1 MQ Telemetry Transport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2.2 WebSphere MQ Telemetry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2.3 Basic concepts of MQTT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.2.4 Comparison between MQTT and HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.2.5 MQTT and Eclipse Paho. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.2.6 MQTT and open source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    1.3 Benefits of using MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.4 Where to use MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    1.4.1 Example implementations of MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.4.2 Machine-to-machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171.4.3 MQTT and sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    Chapter 2. Getting started with MQTT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.1 Clients and brokers used in this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    2.1.1 MQTT clients. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222.1.2 MQTT brokers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    2.2 Scenario used in this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.2.1 Business challenge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.2.2 MQTT-enabled solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    2.3 MQTT concepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262.3.1 MQTT messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262.3.2 Client programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

    2.4 MQTT brokers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282.4.1 Really Small Message Broker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292.4.2 Mosquitto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302.4.3 WMQTT Utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    2.5 Building a sample MQTT application with freely available software . . . . . . . . . . . . . . . 352.5.1 Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.5.2 Building the sample MQTT application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.5.3 Publisher and subscriber in Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.5.4 Publisher and subscriber in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    Copyright IBM Corp. 2012. All rights reserved. iii

  • Chapter 3. Using MQTT with IBM WebSphere MQ Telemetry . . . . . . . . . . . . . . . . . . . . 553.1 Installing, configuring, and managing WebSphere MQ Telemetry . . . . . . . . . . . . . . . . 56

    3.1.1 Before you begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563.1.2 Installing WebSphere MQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573.1.3 Verifying the installation of WebSphere MQ Telemetry . . . . . . . . . . . . . . . . . . . . 593.1.4 Configuring a queue manager for WebSphere MQ Telemetry . . . . . . . . . . . . . . . 653.1.5 Authorizing MQTT clients to access WebSphere MQ. . . . . . . . . . . . . . . . . . . . . . 723.1.6 Enabling the security features of WebSphere MQ for telemetry channels . . . . . . 743.1.7 Configuring WebSphere MQ to send messages to MQTT clients . . . . . . . . . . . . 763.1.8 Performance considerations for WebSphere MQ Telemetry . . . . . . . . . . . . . . . . 77

    3.2 Building a simple solution using WebSphere MQ Telemetry . . . . . . . . . . . . . . . . . . . . 803.2.1 Solution overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803.2.2 Solution implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

    3.3 WebSphere MQ classes for Java Message Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 983.3.1 Sample applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993.3.2 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

    3.4 WebSphere MQ Telemetry daemon for devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053.4.1 Installing and configuring the WebSphere MQ Telemetry daemon for devices . 1073.4.2 WebSphere MQ Telemetry daemon for devices bridges . . . . . . . . . . . . . . . . . . 1073.4.3 Sample implementations of WebSphere MQ Telemetry daemon for devices. . . 109

    3.5 Troubleshooting WebSphere MQ Telemetry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1223.5.1 Location of logs and error files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1233.5.2 Tracing the telemetry service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

    Chapter 4. Integrating MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1274.1 Integrate MQTT with IBM WebSphere Message Broker . . . . . . . . . . . . . . . . . . . . . . . 128

    4.1.1 IBM WebSphere Message Broker versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1284.1.2 Example 1: MQInput node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1294.1.3 Example 2: J