MQTT
MQTT
Bryan Boyd
Joel Gauci
Michael P Robertson
Nguyen Van Duy
Rahul Gupta
Vasfi Gucer
Vladimir Kislicins
ibm.com/redbooks
International Technical Support Organization
October 2014
SG24-8228-00
Note: Before using this information and the product it supports, read the information in “Notices” on
page vii.
This edition applies to IBM MessageSight Version 1.1 and MQTT Version 3.1.
Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Now you can become a published author, too! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Comments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Stay connected to IBM Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii
Chapter 5. IBM MessageSight and the key fob remote application . . . . . . . . . . . . . . 105
5.1 Overview of the key fob remote application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.1.1 Application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.1.2 Testing the key fob remote application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.2 MessageSight configurations for the key fob remote application . . . . . . . . . . . . . . . . 109
5.2.1 MessageSight basic configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.3 Security capabilities of the MessageSight appliance . . . . . . . . . . . . . . . . . . . . . . . . . 119
5.3.1 Adding security controls to the key fob remote application . . . . . . . . . . . . . . . . . 120
5.3.2 Adding security at the transport level using SSL or TLS. . . . . . . . . . . . . . . . . . . 135
Chapter 11. Download, deploy, and run PickMeUp in iOS, Android, and HTML
environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
11.1 Set up a PickMeUp iOS project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
11.1.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
11.1.2 Obtain the PickMeUp iOS source code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
11.1.3 Open the PickMeUp iOS project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Contents v
11.1.4 Configure the project build settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
11.1.5 Run the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.1.6 Run PickMeUp for your iOS project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
11.2 Set up a PickMeUp Android project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
11.2.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
11.2.2 Register with Google Maps API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11.2.3 Android SDK Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11.2.4 Run PickMeUp for your Android project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11.3 Set up the PickMeUp back end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11.3.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11.3.2 Register with Bluemix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
11.3.3 Download, deploy, and run PickMeUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
11.4 Set up the PickMeUp HTML5 project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
This information was developed for products and services offered in the U.S.A.
IBM may not offer the products, services, or features discussed in this document in other countries. Consult
your local IBM representative for information on the products and services currently available in your area. Any
reference to an IBM product, program, or service is not intended to state or imply that only that IBM product,
program, or service may be used. Any functionally equivalent product, program, or service that does not
infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to
evaluate and verify the operation of any non-IBM product, program, or service.
IBM may have patents or pending patent applications covering subject matter described in this document. The
furnishing of this document does not grant you any license to these patents. You can send license inquiries, in
writing, to:
IBM Director of Licensing, IBM Corporation, North Castle Drive, Armonk, NY 10504-1785 U.S.A.
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of
express or implied warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically made
to the information herein; these changes will be incorporated in new editions of the publication. IBM may make
improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time
without notice.
Any references in this information to non-IBM websites are provided for convenience only and do not in any
manner serve as an endorsement of those websites. The materials at those websites are not part of the
materials for this IBM product and use of those websites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring
any obligation to you.
Any performance data contained herein was determined in a controlled environment. Therefore, the results
obtained in other operating environments may vary significantly. Some measurements may have been made
on development-level systems and there is no guarantee that these measurements will be the same on
generally available systems. Furthermore, some measurements may have been estimated through
extrapolation. Actual results may vary. Users of this document should verify the applicable data for their
specific environment.
Information concerning non-IBM products was obtained from the suppliers of those products, their published
announcements or other publicly available sources. IBM has not tested those products and cannot confirm the
accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the
capabilities of non-IBM products should be addressed to the suppliers of those products.
This information contains examples of data and reports used in daily business operations. To illustrate them
as completely as possible, the examples include the names of individuals, companies, brands, and products.
All of these names are fictitious and any similarity to the names and addresses used by an actual business
enterprise is entirely coincidental.
COPYRIGHT LICENSE:
This information contains sample application programs in source language, which illustrate programming
techniques on various operating platforms. You may copy, modify, and distribute these sample programs in
any form without payment to IBM, for the purposes of developing, using, marketing or distributing application
programs conforming to the application programming interface for the operating platform for which the sample
programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore,
cannot guarantee or imply reliability, serviceability, or function of these programs.
The following terms are trademarks of the International Business Machines Corporation in the United States,
other countries, or both:
Bluemix™ IBM® Smarter Planet®
DataPower® InfoSphere® WebSphere®
developerWorks® Redbooks® Worklight®
Global Technology Services® Redbooks (logo) ®
ITIL is a registered trademark, and a registered community trademark of The Minister for the Cabinet Office,
and is registered in the U.S. Patent and Trademark Office.
IT Infrastructure Library is a registered trademark of the Central Computer and Telecommunications Agency
which is now part of the Office of Government Commerce.
Microsoft, Windows, and the Windows logo are trademarks of Microsoft Corporation in the United States,
other countries, or both.
Java, and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its
affiliates.
Other company, product, or service names may be trademarks or service marks of others.
viii Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Preface
MQTT is a messaging protocol designed for the Internet of Things (IoT). It is lightweight
enough to be supported by the smallest devices, yet robust enough to ensure that important
messages get to their destinations every time. With MQTT devices, such as energy meters,
cars, trains, mobile phones and tablets, and personal health care devices, devices can
communicate with each other and with other systems or applications.
IBM® MessageSight is a messaging appliance designed to handle the scale and security of a
robust IoT solution. MessageSight allows you to easily secure connections, configure policies
for messaging, and scale to up to a million concurrently connected devices.
This IBM Redbooks® publication introduces MQTT and MessageSight through a simple key
fob remote MQTT application. It then dives into the architecture and development of a robust,
cross-platform Ride Share and Taxi solution (PickMeUp) with real-time voice, GPS location
sharing, and chat among a variety of mobile platforms. The publication also includes an
addendum describing use cases in a variety of other domains, with sample messaging
topology and suggestions for design.
Authors
This book was produced by a team of specialists from around the world working at the
International Technical Support Organization, Austin Center.
Karen Wallace
International Technical Support Organization, Raleigh Center
Find out more about the residency program, browse the residency index, and apply online at:
ibm.com/redbooks/residencies.html
Comments welcome
Your comments are important to us!
We want our books to be as helpful as possible. Send us your comments about this book or
other IBM Redbooks publications in one of the following ways:
Use the online Contact us review Redbooks form found at:
ibm.com/redbooks
Send your comments in an email to:
[email protected]
Mail your comments to:
IBM Corporation, International Technical Support Organization
Dept. HYTD Mail Station P099
2455 South Road
Poughkeepsie, NY 12601-5400
Preface xi
Stay connected to IBM Redbooks
Find us on Facebook:
http://www.facebook.com/IBMRedbooks
Follow us on Twitter:
http://twitter.com/ibmredbooks
Look for us on LinkedIn:
http://www.linkedin.com/groups?home=&gid=2130806
Explore new Redbooks publications, residencies, and workshops with the IBM Redbooks
weekly newsletter:
https://www.redbooks.ibm.com/Redbooks.nsf/subscribe?OpenForm
Stay current on recent Redbooks publications with RSS Feeds:
http://www.redbooks.ibm.com/rss.html
xii Building Real-time Mobile Solutions with MQTT and IBM MessageSight
1
Before getting into the details of MQTT, let’s take a brief look at the evolving world that
developers who are using MQTT are working to connect.
Note: Starting with Version 3.1.1, MQTT does not stand for Message Queue Telemetry
Transport anymore.
1
The Interconnecting of Everything, an IBM Redbooks Point-of-View publication:
https://www14.software.ibm.com/webapp/iwm/web/signup.do?source=sw-app&S_PKG=ov21861&S_TACT=109KA8NW
To imagine what the IoT might bring about in the next 10 or 20 years, think about the
remarkable things we already can do remotely:
A connected car can predict parts failure and schedule maintenance. Driving habits can
be captured and used for calculating insurance.
A doctor can examine a patient in a distant city and see real-time health status
information, such as blood pressure, heart rate, and so on.
An energy company can monitor windmills in the middle of the ocean and remotely
diagnose and cut off the problematic units.
A homeowner can view his home on a web page, complete with the status of interior
devices, such as the security alarm, heating system, and more.
The IoT will go beyond connecting people to information and to other people. Devices are
interacting with devices, creating what might eventually become a global central nervous
system (Figure 1-2).
The world is already increasingly instrumented, with examples ranging from tiny sensors and
radio-frequency identification (RFID) tags in stand-alone products, through smartphones and
location-aware global positioning system (GPS) devices to notebook PCs and embedded
systems. These devices typically have enough computing power to gather and transmit data,
and certain devices have enough to respond to requests to modify their behavior.
These devices also are nearly all connected to some extent. Most have, or will have, an
Internet address with which they can communicate directly across local networks or indirectly
by way of the cloud. So, the concept of the IoT has already begun to emerge.
The next steps, then, are gathering all of the data that is collected by these small, medium, or
even large devices, routing that data to where it is best interpreted, and using the world’s vast
computational resources to understand what is happening, and to respond as necessary to
improve the quality of life.
People, businesses, and governments are increasingly turning to smart devices and
telemetry to interact more intelligently with the world. A man shopping for groceries wants to
know what is currently in his pantry at home. A woman heading to Austin, Texas, wants to
know whether flights into that city are currently delayed by weather. A motorist driving across
town wants to know whether the main highway is still blocked by the car crash that was
reported on the news. A doctor with a patient due to arrive in the office at 3 p.m. wants to
know, in the morning, whether the patient’s blood pressure is stable enough to make the trip
safely.
Information to help with each of these decisions can be made available from a variety of
smart meters and devices.
Fortunately, these challenges are being overcome through the use of improved telemetry
technologies and communication protocols that are making it possible to send and receive
this information reliably over the Internet, even if the network is unsteady or the monitoring
device has little processing power.
MQTT provides telemetry technology to meet the information challenges of today’s Internet
users.
1.2 MQTT
MQTT is an extremely simple and lightweight messaging protocol. Its publish/subscribe
architecture is designed to be open and easy to implement, with up to thousands of remote
clients capable of being supported by a single server. These characteristics make MQTT
ideal for use in constrained environments where network bandwidth is low or where there is
high latency, and with remote devices that might have limited processing capabilities and
memory.
MQTT minimizes network bandwidth and device resource requirements and also attempts to
ensure reliability and delivery. This approach makes the MQTT protocol particularly
well-suited for connecting machine-to-machine (M2M), which is a critical aspect of the
emerging concept of the IoT.
2
OASIS: Advancing open standards for the information society; for details, visit this website:
https://www.oasis-open.org/org
Publish/subscribe
The MQTT protocol is based on the principle of publishing messages and subscribing to
topics, which is typically referred to as a publish/subscribe model. In this model, clients can
subscribe to topics that pertain to them and therefore receive messages that are published
about those topics. Alternatively, clients can publish messages to topics, therefore making
them available to all subscribers to those topics.
Retained messages
With MQTT, the server keeps the message even after sending it to all current subscribers. If a
new subscription is submitted for the same topic, any retained messages are then sent to the
new subscribing client.
Experience with messaging and events across many industry domains has identified key
requirements for such a messaging protocol:
The protocol needs to provide bidirectional messaging support to uniformly handle both
signals and commands. Additionally, the protocol is required to deliver messages to and
from constrained devices that are connected over networks that have limited bandwidth.
Basic QoS levels are needed to reflect trade-offs among bandwidth, availability, and
delivery guarantees. A subscriber must be able to set up a QoS that works in conjunction
with the available constraints.
Connectivity cognizance to support intermittently connected networks and devices. The
publish/subscribe infrastructure needs to provide message subscribers and, if necessary,
a means for making a decision about likely connected, disconnected, and error states of
the end devices in the network.
Loose coupling is required to support dynamic system environments, where a heavy influx
of messages and events needs to be made available to enterprise applications and other
consumers in an unanticipated manner. Time, space, and synchronization decoupling is
needed.
For more details about the OASIS MQTT Technical Committee, visit this website:
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=mqtt
One of the major objectives of the Eclipse Paho project is to provide an effective level of
decoupling between the device and applications. The project initially started with MQTT
publish/subscribe client implementations for use on embedded platforms, but in the future, it
will bring corresponding server support as determined by the community.
For M2M devices and client developers to integrate, develop, and test messaging
components end-to-end, the Eclipse Paho project provides the framework to support the
testing and development of end-to-end device connectivity with a server. The MQTT
application described in this chapter uses the Java client implementation from the Eclipse
Paho project.
3
The Paho project: http://www.eclipse.org/paho/
4 IoT.eclipse.org is making the Internet of Things (IoT) development simpler: http://iot.eclipse.org/
For more details about the Eclipse Paho project, see this website:
http://www.eclipse.org/paho
Information is also available about the MQTT V3.1 Java and C clients, which IBM contributed,
and which you can download from the following web pages:
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.c.git/
Message size Small, with a compact binary header Larger, partly because status detail
that is just two bytes in size is text-based
Service levels Three QoS settings All messages get the same level of
service
Extra libraries Libraries for C (30 KB) and Java Depends on the application
(100 KB) (JavaScript Object Notation (JSON)
or Extensible Markup Language
(XML), but typically not small
An actual example occurred at Facebook with their Facebook Messenger5 product. Engineers
implemented the MQTT protocol instead of HTTP, because the users experienced latency
problems when sending messages. Message delivery was reliable but slow with HTTP. A new
mechanism was needed for maintaining a persistent connection with the messaging servers
without consuming too much battery power. This is critical to users of the company’s social
networking site, because so many use battery-powered mobile devices. The company’s
developers solved the problem by using the MQTT protocol. By maintaining an MQTT
connection and routing messages through its chat pipeline, message delivery was
accomplished at speeds of just a few hundred milliseconds, rather than multiple seconds.
1.3 MessageSight
IBM provides a suite of messaging products that helps businesses to meet the demands of
today’s interconnected world. By using the IBM portfolio of messaging products, you can
achieve a solution that extends from back-end enterprise applications to include millions of
mobile users. MessageSight is one of the latest additions to the IBM messaging family. It is an
appliance-based messaging server that is optimized to address the massive scale
requirements of M2M and mobile use cases. MessageSight is designed to sit at the edge of
the enterprise and can extend your existing messaging infrastructure or be used stand-alone.
MessageSight joins the IBM portfolio of middleware to help bridge back-end enterprise
environments to remote smart clients as the planet becomes more digitally interconnected.
This allows organizations to provide an interactive experience with users and offer real-time
analytics of large data volumes (Figure 1-4).
The MessageSight appliance is built for high performance to offer persistent, transactional
messaging. This hardware is 2U form factor and can connect to a 1 GbE, 10 GbE, or 40 GbE
network. MessageSight includes built-in security, and permits integration with external
Lightweight Directory Access Protocol (LDAP) security systems.
5
Building Facebook Messenger; Lucy Zhang, August 12, 2011:
https://www.facebook.com/notes/facebook-engineering/building-facebook-messenger/10150259350998920
Mobile application support is provided by MessageSight, and so, it can handle massive
scaling of concurrent device connectivity and communication, offering high performance
messaging. The appliance is demilitarized zone (DMZ) ready, allowing you to securely extend
your existing messaging enterprise. The device can act as the gateway for business data that
flows in and out of your enterprise network.
MessageSight is developer friendly, designed for easy deployment and easy integration. This
book explores how MessageSight can be integrated with other IBM offerings to deliver a
complete messaging solution that encompasses remote mobile clients and back-end
enterprise systems.
The MessageSight appliance can be used either with the MQTT protocol for low latency
publishing and subscribing (ideal for machine-to-machine (M2M)), or with the Java Message
Service (JMS) to transfer messages received from remote clients to back-end applications.
Figure 1-5 on page 14 shows examples of how clients who are connected to MessageSight
can interface with WebSphere MQ and other back-end applications. Here, you can see that
MessageSight connects many users and devices on the Internet to services that are
deployed on an intranet. The users, devices, and services interact with each other by
exchanging messages through the appliance.
MQTT was designed to overcome these limitations and issues and includes the following
underlying principles:
Simplicity: The protocol was made open so that it can be integrated easily into other
solutions.
Use of the publish/subscribe model: The sender and the receiver are decoupled.
Therefore, publishers do not need to know who or what is subscribing to messages, and
vice versa.
Minimal maintenance: Features, such as automated message storage and
retransmission, minimize the need for administration tasks.
Limited on-the-wire footprint: The protocol keeps data that is overhead to a minimum on
every message.
Continuous session awareness: By being aware of when sessions have terminated, the
protocol can take action accordingly, thanks in part to a will feature.
Local message processing: The protocol assumes that remote devices have limited
processing capabilities.
Message persistence: Through the designation of a specific QoS, the publisher can ensure
delivery of the most important messages.
Agnostic regarding data type: The protocol does not require that the content of messages
is in any particular format.
Automated Chemical and petroleum A homeowner uses smart metering to obtain a more
metering Energy and utilities accurate view of how each household appliance
consumes electricity and how to make changes.
An oil company monitors the gasoline sump levels at
a gas station in real time and schedules a gasoline
delivery when the sumps are nearing empty.
Health care quality Pharmaceutical A medical clinic remotely tracks the vital signs of
and resource Medical research at-risk patients to help prevent sudden crises that
tracking Hospitals might arise after a patient goes home.
Nursing homes A research team monitors chemical reactions in a
Waste management remote laboratory and alerts the chemist when a
particular result or stage of development is
achieved.
A waste management company can be notified
when the trash can is full and can be notified for
pickup.
MQTT and MessageSight facilitate message routing, allowing the car to send diagnostic
information to the automobile company. The car basically acts as a rolling sensor platform
that publishes telemetric events. The MQTT protocol is used to transport data from the car
sensors to the automobile company. This data can be analyzed using predictive maintenance
analytics, acting as a virtual mechanic, which then sends a notification to the customer that
service is needed before a component fails.
Also, the car can receive messages ranging from remotely locking the car, setting the climate
controls (heat or air), or requesting that the car send its current location. Most existing
connected car solutions have previously taken a mobile response time measured in tens of
seconds. Tests with MessageSight using MQTT have shown the response time to be less
than one second, equal to the time it takes to push a key fob.
In the connected city example depicted in Figure 1-7, it is easy to see how millions of cars
sending messages can create a massive amount of data to be processed. To date, capturing
and analyzing this amount of data in real time was a technical challenge. Using
MessageSight in conjunction with IBM InfoSphere® Streams, stream computing helps to
alleviate this dilemma by allowing real-time analytics to be performed on big data.
Other convenience features of the connected home are that a homeowner can adjust the
thermostat or unlock a door using a mobile device. These types of features not only offer
convenience; they also help to contribute to a Smarter Planet environment by being able to
lower utility usage, as needed. The ability to remotely manage door locks and utilities can
apply to a rental or vacation property, as well.
For example, if a customer is browsing a product at home on a mobile device, then enters a
retail store, the retailer’s mobile application can be used to find where the product is located in
the store. The retailer might even want to push a notification for a sale or discount on that or a
similar product when the customer is browsing in the store.
The retailer can enable business rules to handle database calls, analytics, pricing, and so on
to cater to notifications that are based on the individual consumer, even the consumer’s
current geographic location. The retailer’s central office is able to monitor the millions of
messages using MessageSight.
Publish/subscribe pattern
MQTT uses a publish/subscribe messaging pattern that enables a loose coupling between
the information provider, called the publisher, and consumers of the information, called
subscribers. This is achieved by introducing an MQTT server between the publisher and the
subscribers; Figure 2-1 illustrates the publish/subscribe example.
Compared with the traditional point-to-point pattern, the advantage of the publish/subscribe
model is that the publishing device or application does not need to know anything about the
subscribing one, and vice versa. The publisher simply sends the message with an identifier
that denotes its topic, or subject area. The MQTT server then distributes the message to all
applications or devices that have chosen to subscribe to that topic. In this way, the
publish/subscribe pattern turns traditional point-to-point messaging into a multicast of
content-based communications.
MQTT client
The MQTT client is a program or device that implements and uses the MQTT protocol. An
MQTT client always establishes the network connection to the MQTT server. MQTT clients
can act as a publisher or a subscriber. An MQTT client can perform these functions:
Publish application messages that other MQTT clients might be interested in
Subscribe to request application messages that it is interested in receiving
Unsubscribe to remove a request for application messages
Disconnect from the MQTT server
MQTT server
The MQTT server is a program or device that acts as an intermediary between MQTT clients
that publish application messages and MQTT clients that have made subscriptions. An MQTT
server can perform these functions:
Accepts network connections from clients
Accepts application messages published by clients
Processes subscribe and unsubscribe requests from MQTT clients
Forwards application messages that match MQTT client subscriptions
Topics
Publishers are responsible for classifying their message subjects into topics. A topic defines
the content of a message or the subject area under which the message can be categorized.
In our scenario, the simplest example of a topic is the single word sports. Topics are important
because, when messages in point-to-point systems are sent to specific destination
addresses, messages in publish/subscribe systems, such as MQTT, are distributed based on
each subscriber’s choice of topics. By subscribing to a particular topic, the subscriber is
signing up to receive every message published to that topic from any publisher.
Topic trees
Typically, topics are organized hierarchically into topic trees that use the forward slash (/)
character to create subtopics in the topic string. In our scenario, an example of a simple topic
tree is sports/tennis/wimbledon.
Topic strings
A topic string is a character string that identifies the topic of a publish/subscribe message.
Topic strings can contain either of two wildcard schemes to allow subscribers to match
patterns within strings defined by message publishers:
Multilevel: The wildcard character number sign (#) is used to match any number of levels
within a topic. For example, subscribers to sports/tennis/# receive all messages that are
designated for the topics sports/tennis/wimbledon and sports/tennis/usopen.1
1
All the scoreboards are sponsored and developed by IBM using IBM MessageSight at both the US Open and
Wimbledon: US Open - http://www.usopen.org/en_US/scores/index.html?promo=subnav and Wimbledon -
http://www.wimbledon.com/en_GB/scores/
Client identifier
The client identifier is a 23-byte string that identifies an MQTT client. Each identifier must be
unique to only one connected client at a time. To keep the identifier short and unique,
developers typically introduce an identifier generation mechanism, such as creating it from
the 48-bit device message authentication code (MAC) address. If transmission size is not a
critical issue, the application might use the remaining 17 bytes to make the address easier to
administer by inserting some human-readable text in the identifier, for example.
Retained publications
Publications (messages) for a given topic can be retained and delivered when new
subscribers sign up for the topic. Publishers must set a retention attribute for each message;
a setting of true retains the message and a setting of false establishes that the message will
not be retained for future delivery. When a publication to be retained is created or updated, it
is given a quality of service (QoS) designation of at least once (QoS=1) or exactly once
(QoS=2). If a publication is sent with a QoS setting of at most once (QoS=0), a nonpersistent
retained publication is automatically created and the publication is not retained if the queue
manager stops.
Use retained publications to record the latest value of a measurement. New subscribers to
the retained topic immediately receive the most recent value of the measurement. If no new
measurements have been taken since the subscriber last subscribed to the publication topic,
the subscriber still receives the most recent retained publication on the topic the next time the
subscriber connects.
For publications, the clean session setting only affects publications sent with designations of
QoS=1 and QoS=2. Using cleanSession=true might result in losing a publication, because it
drops all publications that have not been received.
For subscriptions, if cleanSession=true, any old subscriptions for the client are removed
when the client connects. Any new subscriptions the client makes during the session are
removed when it disconnects.
You can download the developer’s evaluation image of IBM MessageSight v1.0.0.1 from the
following website:
http://ibm.co/1qzajLo
2.2.3 Really Small Message Broker and MQ Telemetry daemon for devices
Really Small Message Broker (RSMB) is a small, no-charge C implementation of an MQTT
broker. It also is an advanced MQTT V3 client application. Developers usually use it as a hub
to store and forward messages from MQTT clients to a back-end MQTT broker. RSMB, which
was first released in 2003, can be downloaded as a stand-alone client here:
https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?source=AW-0U9&S_PKG=
0U9
2.2.4 Mosquitto
Mosquitto is a small, no-cost, open source implementation of an MQTT server that supports
the MQTT V3.1 protocol. Mosquitto replicates the functionality of Really Small Message
Broker.
Client libraries can simplify the process of writing MQTT client applications. For example, the
Eclipse Paho project provides Java and JavaScript client libraries that can be used to enable
the MQTT V3 protocol for use on a number of platforms. When these libraries are
incorporated into MQTT applications, a fully functional MQTT client can be created with just a
few lines of code.
The Eclipse Paho project initially started with MQTT publish/subscribe client implementations
for use on embedded platforms, but in the future will provide corresponding server support as
determined by the community. The current efforts of the Eclipse Paho project are to support
the requirements of M2M integration with web and enterprise middleware and applications.
For M2M devices and client developers to integrate, develop, and test messaging
components end to end, the Eclipse Paho project provides a framework to support testing
and development of end-to-end device connectivity with a server. The MQTT client examples
demonstrated in this chapter use the Java and JavaScript client libraries from the Eclipse
Paho project.
The Eclipse Paho MQTT clients can be downloaded from this website:
http://www.eclipse.org/paho/download.php
The asynchronous API supports a different style in which a call returns immediately. The
application can then either be notified through a callback when the operation completes, or
can use a token returned to the application to block until the operation completes. This style
of API is better suited to mobile, event-oriented, and high-performing applications.
Applications where it might take time to complete an operation, or where a thread must not be
blocked, are good candidates for the asynchronous API.
This client is a version of the open source MQTT client that is available from the Eclipse Paho
project.2
For new applications, use the client in the org.eclipse.paho.client.mqttv3 package. To use
this library, the Eclipse Paho version of the client (org.eclipse.paho.client.mqttv3v3.jar)
must be included on the class path.
2.3.3 Preparation
The Java and JavaScript clients from the Eclipse Paho project are distributed as source code.
Therefore, developers need to compile these clients on their own. The Eclipse Paho client
source code is in a Git repository, and Git must be installed on the system before the
compiling process is begun.
Note: We used a Microsoft Windows 7 machine to download the Java client, and the
libraries were downloaded to, in our case, the following location:
4. This will build the client library without running the tests. The jars for the library, source,
and Javadoc are in org.eclipse.paho.client.mqttv3/target. Figure 2-2 shows the
target folder containing the Java library for Eclipse Paho.
5. When the build is complete, Maven shows the build output as shown in Example 2-3.
Alternatively, the JavaScript client can be downloaded directly from the project’s Git
repository:
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git/plain/src/mqttw
s31.js
The build script of the Eclipse Paho JavaScript client requires the Apache Maven automated
software build tool:
1. Download and install Apache Maven from the following website:
http://maven.apache.org/download.cgi
2. Start at the console and enter the command shown in Example 2-4 to get the source code
from the Git repository.
Note: We used a Windows 7 machine to download the Java client and the libraries
were downloaded to, in our case, following location:
The next two sections describe how to build an MQTT client application that can publish and
subscribe to topics. Examples are provided for Java, JavaScript, and HTML5.
The following general steps are performed when creating the applications:
1. Create an instance of an MQTT client.
2. Prepare connection options and connect to the MQTT server using these options.
3. Publish messages to topics, and subscribe to topics.
4. Disconnect from the MQTT server.
Publisher application
The publisher application consists of two Java classes, as described in Table 2-1.
Example 2-6 on page 31 shows the Java class MQTTPublisherConstants. It is used to set the
connection and other publication-related configuration information.
Example 2-7 shows the Java class MQTTPublisher. This class uses the Eclipse Paho Java
APIs for the publication of messages about different topics.
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
try {
//a. Create an instance of MQTT client
MqttClient client = new MqttClient(MQTTPublisherConstants.TCPADDRESS,
MQTTPublisherConstants.CLIENTID);
catch (Exception e) {
e.printStackTrace();
}
}
After starting the MQTTPublisher application, a message displays in the console window,
similar to the messages shown in Example 2-8 on page 34, which means that the message
was delivered to the MQTT server successfully.
Subscriber application
The subscriber application consists of three Java classes, as described in Table 2-2.
Example 2-9 shows the Java class MQTTSubscriberConstants and how it is used to set the
connection and other subscription-related configuration information.
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttException;
Example 2-11 on page 36 shows the class MQTTSubscriber. This class creates the
subscription and waits for matching publications. The handling of the actual message is
delegated to the Callback class, which is defined in MQTTSubscriberCallback.java in
Example 2-10. MQTTSubscriber.java uses an asynchronous programming model, which
means it does not need to wait for a message to arrive and block the execution of the
program.
import java.util.Scanner;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
try {
//a. Create an instance of MQTT client
MqttClient client = new MqttClient(MQTTSubscriberConstants.TCPADDRESS,
MQTTSubscriberConstants.CLIENTID);
} catch (Exception e) {
e.printStackTrace();
}
}
}
After starting the MQTTSubscriber application, a message is seen in the console window,
similar to the messages shown in Example 2-12, which means that the application started
successfully and received a message sent by the publisher.
The MQTT publisher and subscriber application for Java can be downloaded from the
hyperlink included in Appendix B, “Additional material” on page 245.
The JavaScript MQTT publisher and subscriber application described in this section uses the
Eclipse Paho JavaScript library. The JavaScript library consists of three objects, as described
in Table 2-3 on page 39.
Messaging Namespace You can send and receive messages using web browsers. This programming
interface lets a JavaScript client application use the MQTT V3.1 protocol to
connect to an MQTT-supporting messaging server. The following functions
are supported:
Messaging.Client Class This class contains methods that provide the functionality of the API, including
the provision of callbacks that notify the application when a message arrives
from or is delivered to the messaging server, or when the status of its
connection to the messaging server changes.
Messaging.Message Class This class encapsulates the payload of the message, with various attributes
associated with its delivery, in particular the destination to which it has been
(or is about to be) sent.
Publisher application
The publisher application is implemented in the WebSocket/publisher.js file. Example 2-13
shows the implementation of this JavaScript application.
function doConnect(form) {
client = new Messaging.Client(form.serverName.value.trim(),
parseFloat(form.serverPort.value), clientId);
client.onConnectionLost = onConnectionLost;
client.connect({onSuccess : onConnect});
}
function doPublish(form) {
var message = new Messaging.Message(form.newsMessage.value);
message.destinationName = "sports/tennis/wimbledon";
form.newsMessage.value="";
client.send(message);
}
function doDisconnect() {
clearAll();
client.disconnect();
}
function clearAll() {
var form = document.getElementById("publisher");
form.serverName.value = "";
form.serverPort.value = "";
form.newsMessage.value = "";
// Messaging callbacks
function onConnect() {
var form = document.getElementById("publisher");
form.connected.checked = true;
form.serverName.disabled = true;
form.serverPort.disabled = true;
form.newsMessage.disabled = false;
form.publishButton.disabled = false;
form.disconnectButton.disabled = false;
}
function onConnectionLost(responseObject) {
var form = document.getElementById("publisher");
form.connected.checked = false;
if (responseObject.errorCode !== 0)
alert(client.clientId + "\n" + responseObject.errorCode);
}
The client is created with the Domain Name System (DNS) host name and port to which it is
going to connect. It also needs to know the unique client identifier that will identify the client to
the server. In Example 2-13 on page 39, we used the host name and port number that are
entered through the HTML web page so the client makes a connection back to the same
server.
Next, the callbacks are set for a successful connection and when the connection is lost, this is
coded using the following snippets:
client.connect({onSuccess : onConnect});
client.onConnectionLost = onConnectionLost;
These callbacks are driven when the connection is successfully established or when the
connection is lost. Web browsers do not allow method calls to block so we need to rely on
callbacks to notify us when an action is complete.
After the publisher application is connected to the server, a message can be created and
published to a specific topic using the following code snippet:
var message = new Messaging.Message(form.newsMessage.value);
message.destinationName = "sports/tennis/wimbledon";
client.send(message);
client.disconnect();
Figure 2-4 shows the publisher application opened in a web browser for publishing
tennis-related news.
To execute this application, enter the MessageSight server name and the port number for
endpoints, and click Connect. After the application is connected, the news publisher can
publish related news messages, as shown in Figure 2-5 on page 42. To disconnect the
application, click Disconnect.
Subscriber application
The subscriber application is implemented in the WebSocket/subscriber.js file.
Example 2-14 shows the implementation of this JavaScript application.
function doConnect(form) {
client = new Messaging.Client(form.serverName.value.trim(),
parseFloat(form.serverPort.value), clientId);
client.onMessageArrived = onMessageArrived;
client.onConnectionLost = onConnectionLost;
client.connect({onSuccess : onConnect});
}
function doSubscribe(form) {
client.subscribe("sports/tennis/+");
form.newsMessage.disabled = false;
}
function doDisconnect() {
clearAll();
client.unsubscribe("sports/tennis/+");
client.disconnect();
}
// Messaging callbacks
function onConnect() {
var form = document.getElementById("subscriber");
form.serverName.disabled = true;
form.serverPort.disabled = true;
form.connected.checked = true;
form.subscribeButton.disabled = false;
form.disconnectButton.disabled = false;
}
function onConnectionLost(responseObject) {
var form = document.getElementById("subscriber");
form.connected.checked = false;
if (responseObject.errorCode !== 0)
alert(client.clientId + "\n" + responseObject.errorCode);
}
function onMessageArrived(message) {
var form = document.getElementById("subscriber");
addText(form,message);
}
The client is created with the DNS host name and port to which it is going to connect. It also
needs to know the unique client identifier that will identify the client to the server. In
Example 2-14 on page 42, we used the host name and port number that are entered through
the HTML web page so the client makes a connection back to the same server.
These callbacks are driven when the connection is successfully established, when the
connection is lost, or when the message arrives for the application. Web browsers do not
allow method calls to block so we need to rely on callbacks to notify us when an action is
complete.
The subscriber application subscribes to a topic for receiving messages that are published on
that topic. The following code snippet shows the subscription request for the topic filter
"sports/tennis/+".
client.subscribe("sports/tennis/+");
When the application is subscribed to a topic, any messages published on that topic will be
sent to this application.
The application might choose to unsubscribe and disconnect from the server, and this can be
done using the following code snippet:
client.unsubscribe("sports/tennis/+");
client.disconnect();
Figure 2-6 on page 45 shows the subscriber application opened in a web browser to
subscribe for tennis-related news.
To execute this application, enter the MessageSight server name and port number for
endpoints and click Connect. After the subscriber application is connected to MessageSight
appliance, click Subscribe to subscribe on the tennis news topics. Any news publication
published on the subscribed topic will be received by this application. Figure 2-7 on page 46
shows the news message received by the server. To disconnect the application, click
Disconnect.
MQTT clients can be implemented in different programming languages. To read more about
the MQTT specification, see Appendix A, “The MQTT protocol” on page 235.
The Internet is transitioning to the Internet of Things (IoT), where things or machines, connect
to machines (M2M), and interact with reduced, if any, human intervention. With the numbers
of devices in use increasing, organizations require a scalable, reliable, and cost-effective
solution for connecting these devices to their system of records.
The IBM MessageSight messaging appliance helps to deliver the performance, value, and
simplicity that organizations need for accommodating this multitude of devices and
processing large volumes of events in real time.
The explosion in the number of mobile devices, such as smartphones and tablets, is creating
many endpoints. Consumers expect real-time communication between their devices and
applications. Building these applications relies on a scalable, bidirectional communication
infrastructure. Emerging standards, such as HTML5 web sockets, provide the basis for
building rich mobile, intranet, and Internet applications.
Note: MQTT is a messaging protocol designed for wireless networks and devices with
which conserving device battery life, reducing network traffic, and delivering reliable
messages over unreliable networks are key. MQTT is an open protocol with no-cost MQTT
clients available for a wide range of mobile platforms.
For details about the MQTT protocol, see Appendix A, “The MQTT protocol” on page 235.
Figure 3-1 shows the wireless MQTT protocol as it connects to MessageSight, inside an
enterprise network.
Figure 3-1 The wireless MQTT protocol connects to MessageSight, inside an enterprise network
Because of the efficiency of the MQTT messaging protocol, which is faster and requires less
bandwidth and less battery power than traditional HTTP, MessageSight is optimized for
wireless clients. The event-oriented paradigm provides for a better customer experience. The
developer-friendly application programming interfaces (APIs) and libraries can be used for a
variety of mobile OSs, including Google’s Android and Apple’s iOS.
Note: Developers can use a version of the MessageSight virtual appliance that is available
at no charge from the IBM Mobile and machine-to-machine (M2M) community:
https://www.ibm.com/developerworks/community/blogs/c565c720-fe84-4f63-873f-607d
87787327/entry/ibm_messagesight_for_developers_is_here?lang=en
Figure 1-5 on page 14 shows examples of how clients who are connected to MessageSight
can interface with WebSphere MQ and other back-end applications.
MessageSight supports client applications using specific protocols. At the time of publishing,
IBM provides the following clients for these protocols:
MQTT over TCP/IP:
– MQTT C client
– MQTT client for Android
– MQTT client for Java
– MQTT client for iOS
MQTT over websockets
MQTT client for JavaScript
JMS
MessageSight JMS client
publisher
subscribers
One use of this pattern is when broadcasting data related to the location of a connected
vehicle. As an example, this is useful for broadcasting an updated vehicle position.
IBM
MessageSight
subscriber
publishers
One use of this pattern is when receiving data from a number of sensors. As an example, this
is useful when receiving data from earthquake sensors.
IBM
topic #1
MessageSight topic #1
topic #2 topic #2
topic #N topic #N
publisher
subscribers
One use of this pattern is when sending control commands to a device. As an example, this is
useful when sending a command to an application to activate a feature.
For this messaging pattern, each subscriber must subscribe to a unique topic. By using the
unique client ID, group ID, or user ID of the subscribing application in the topic string, you can
ensure that each topic is unique. For example, a subscriber application instance that
connects with client ID 123 subscribes to RESPONSE/123. A subscriber application instance that
connects with client ID 456 subscribes to RESPONSE/456. A subscriber application instance
with client ID 789 subscribes to RESPONSE/789.
To ensure that subscribers cannot access topics of other subscribers, you can use the topic
string variable substitution that is available in MessageSight messaging policies. By using
topic string variable substitution, you can create a messaging policy with a single topic string
that includes a user ID, group ID, or client ID variable.
This substitution ensures that applications can subscribe only to the topic string that matches
their user ID, group ID, or client ID. For example, a topic string of RESPONSE/${ClientID} is
specified in the messaging policy. The application with client ID 123 is allowed to subscribe to
RESPONSE/123, but is not allowed to subscribe to RESPONSE/456 or RESPONSE/789 because the
client IDs do not match.
IBM
MessageSight
topic #1 topic #1
topic #2 topic #2
topic #N topic #N
publisher
subscribers
One use of this pattern is when a control center is interrogating the state of a device. As an
example, this is useful when requesting a temperature reading from a sensor.
topic #2 topic #2
topic #N topic #N
subscriber
1 subscriber subscribes
and publishes to each
many internet devices publish
unique topic strings
and subscribe to a unique topic string
One use of this pattern is when a device is polling a control center for information updates. As
an example, this is useful when polling for information about firmware updates.
This virtual edition is to be used in a development environment only. The benefit of this
developer-focused virtual appliance is that it enables rapid application development. It
enables developers to get started quickly in coding and testing applications to work with
MessageSight. This virtual appliance is suitable for deploying in IBM VMware and Oracle
VirtualBox environments.
Note: All details regarding the installation of the MessageSight physical appliance
installation are in the publication, Responsive Mobile User Experience Using MQTT and
IBM MessageSight, SG24-8183.
Note: Developers can use the version of the MessageSight virtual appliance that is
available at no charge from the IBM Mobile and M2M community:
https://www.ibm.com/developerworks/community/blogs/c565c720-fe84-4f63-873f-607d
87787327/entry/ibm_messagesight_for_developers_is_here?lang=en
Note: At the time of publishing, the latest release of the MessageSight virtual appliance
is 1.1. Therefore, the OVA file to import is IBMMessageSightV1.1.ova.
Wait for the end of the import process. The import process might take several minutes to
complete.
6. Define the settings for the newly imported MessageSight virtual image. The minimum
requirements to run the MessageSight virtual appliance are listed:
– Memory: 4 GB
– Processors: 2
– Hard disk: 16 GB
– Network settings: In this installation example, we use a network address translation
(NAT) network adapter. The NAT is configured to use the dynamic host configuration
protocol (DHCP), but you can choose any network adapter type. If you are not using
DHCP, see the MessageSight Ethernet interfaces configuration guide available in the
MessageSight IBM Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.0.0/com.ibm.ism.doc/A
dministering/ad00212_.html
7. Click the Power on this virtual machine link.
Wait for the virtual machine to start. This might take a couple of minutes.
Figure 3-7 shows the start of the boot process of the MessageSight virtual appliance.
Figure 3-7 The boot process begins on the MessageSight virtual appliance
12.Enter yes and press Enter to select DHCP rather than assigning a fixed address.
13.Press Enter to confirm the selection, as shown in Figure 3-10.
14.The interface is configured using DHCP. Record the assigned address. This address is
used to communicate with the appliance.
The command ethernet-interface eth0 can be used to display the address assigned to
an Ethernet port, as shown in Figure 3-11.
Note: If you make a mistake in configuring the value of eth0, type the following command
at a command prompt and make the necessary corrections:
Note: All details regarding the installation of the MessageSight physical appliance
installation are in the Redbooks publication, Responsive Mobile User Experience Using
MQTT and IBM MessageSight, SG24-8183.
The host name or IP address of the MessageSight appliance is required to access the web
UI. The HTTPS protocol is used to secure the communication between appliance users and
the MessageSight appliance.
Note: The default listening port of the MessageSight web UI is 9087. This value is
configurable.
Use the following steps to connect to the MessageSight appliance using the web UI:
1. Open a supported web browser and enter the following URL:
https://<MessageSight_HostName_Or_IPAddress>:9087
2. Accept the MessageSight self-signed certificate, and the login window shown in
Figure 3-12 on page 58 opens.
3. Enter the login and password to access the MessageSight web UI. The default values are
shown:
– Login: admin
– Password: admin
4. View and accept the software licensing agreement that displays at your first connection to
the web UI.
The MessageSight web UI First Steps tab displays. Here, you can configure the range for
Ethernet client connections, and configure a default gateway, or change the default
password for the administrator account, as shown in Figure 3-13 on page 59. To change
the default administrator password at a later time, see “Reset an existing password (all
user roles)” on page 69.
Note: Use the Classless Inter-Domain Routing (CIDR) notation to define the IP address
range property.
5. Click Save and Close to save and close your changes, and click the Home tab to display
the MessageSight web UI home page, as shown in Figure 3-14 on page 60.
This panel guides you through the configuration and test of the following elements:
– Verify your network configuration with the MessageSight Messaging Tester
The Messaging tester is a simple graphical tool that can help to test the connections to
a network interface of a MessageSight appliance. The Messaging Tester is a web client
based on JavaScript, which uses MQTT over websockets for communications with
MessageSight through one of its network interface adapters.
Using the Messaging Tester, you can configure up to five MQTT clients that are
executing publications and subscriptions, as shown in Figure 3-16 on page 62.
The following sections describe the execution of several basic administration tasks using the
MessageSight web UI.
Figure 3-19 Display the firmware version using the About menu
A window displays the firmware version and build number, as shown in Figure 3-20 on
page 65.
Second method
Only MessageSight administrators can use this method for displaying the firmware
version. For a description of all user roles available in MessageSight, see “User roles and
configuring users” on page 66.
Connect to MessageSight using the web UI, and select Appliance System Control, as
shown in Figure 3-21 on page 66.
For further details about the actions that each type of appliance user can perform, see the
following URL:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Securit
y/se00001_.html?lang=en
Figure 3-23 Access is denied to the MessageSight CLI for users other than system administrators
Configure users
To add, edit, or delete appliance users, complete these steps. This process can be performed
only by a system administrator:
1. Connect to the MessageSight web UI using the administrator account. The Home page
opens.
2. Under Create users and groups, select Appliance Users, as shown in Figure 3-24.
Figure 3-24 Create appliance users from the web UI Home page
The list of existing appliance users displays, as shown in Figure 3-25 on page 68.
Other ways to add, edit, or delete users, including resetting passwords, are shown:
Add a user:
Click the plus sign (+) icon. In the window that opens, enter a user name and password,
and select a group name to associate the user with: SystemAdministrators, Users, or
MessagingAdministrators.
Edit a user password:
Select the user to edit and click the pencil (edit) icon.
Delete a user:
Select the user to delete and click the delete (red cross) icon.
Figure 3-28 Change the administrator password from the admin user menu
Any user who is logged in to MessageSight through the web UI can change their password
using the Change Password link that displays in the user menu for that user.
Note: All details related to the installation of the MessageSight physical appliance are in
the Redbooks publication, Responsive Mobile User Experience Using MQTT and IBM
MessageSight, SG24-8183.
If you have installed a physical appliance, you can access the MessageSight CLI locally using
a keyboard, video, and mouse (KVM) console, or over the network using serial over local area
network (LAN) or SSH.
If you have installed a virtual MessageSight appliance, you can access that CLI directly from
your hypervisor solution, if you have an administrator name and password, or by using SSH,
as well.
For this discussion, we access the MessageSight appliance CLI using an SSH client.
Note: Access the MessageSight V1.1 Command Reference guide in the MessageSight
IBM Knowledge Center website:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/R
eference/intro.html
Example 3-2 Determine your machine type and serial number using the CLI
Console>
Console> show version
Installation date: Dec 4, 2013 8:54:50 PM
Platform version: 5.0.0.19
Platform build ID: build22-20131007-1001
Platform build date: 2013-10-07 14:08:05+00:00
Machine type/model: 7915AC1
Serial number: KQ2H7YC
Entitlement: KQ2H7YC
Firmware type: Release
Console>
You might notice a difference for the Machine type/mode output value if you apply the same
show version command on a MessageSight virtual appliance. This is shown in Example 3-3
on page 72.
Example 3-4 Determine the status of an Ethernet interface using the CLI
Console>
Console> status ethernet-interface eth0
eth0 OpState:[Up]
generic MTU:1500 carrier:true
flags:UP BROADCAST RUNNING MULTICAST index:5
inet addr:192.168.198.40 flags:PERMANENT mask:255.255.255.0
scope:GLOBAL
inet6 addr: fe80::20c:29ff:fe83:fc5a flags:PERMANENT
mask: ffff:ffff:ffff:ffff:: scope:LINK
ethernet Link:on MAC: 00:0c:29:83:fc:5a autoneg:on duplex:Full
port:TP speed:1000Mbps
statistics collisions:0 multicast:0 rx_bytes:2330429
rx_compressed:0 rx_crc_errors:0 rx_dropped:0 rx_errors:0
rx_fifo_errors:0 rx_frame_errors:0 rx_length_errors:0
rx_missed_errors:0 rx_over_errors:0 rx_packets:22383
tx_aborted_errors:0 tx_bytes:48742 tx_carrier_errors:0
tx_compressed:0 tx_dropped:0 tx_errors:0 tx_fifo_errors:0
tx_heartbeat_errors:0 tx_packets:354 tx_window_errors:0
Console>
Console>
Console> nodename set imaDev
Console>
To determine the node name of an appliance, use the nodename get command, as shown in
Example 3-6 on page 73.
Example 3-7 Determine the firmware version of a MessageSight appliance using the CLI
Console> show imaserver
MessageSight version is 1.1 20131112-0402 2013-11-11 23:04
Console>
The platform must-gather command is used for troubleshooting, and for collecting the
must-gather diagnostic data for reporting a problem to the MessageSight support team when
generating a problem management record (PMR). Sending the output from the platform
must-gather command helps the MessageSight support team to resolve your problem more
quickly.
To collect this output, complete the following steps:
1. Access the MessageSight CLI.
2. Run the platform must-gather command to create a .tgz file containing diagnostic
information. If you have a PMR open with IBM, include that number in the file name.
Console> platform must-gather PMR-12345,67R,890-Jul16.tgz
3. Run the file list command. You will see the file that you created, and a separate
collect-pd.txt file, as shown in Example 3-8.
4. Send the output from the platform must-gather command to the MessageSight support
team as part of a PMR problem ticket.
If the server is stopped, start the server by entering the following command:
Console> imaserver start
2. Set the server to maintenance mode by entering the commands shown in Example 3-10.
3. Create a secure backup of the appliance by using the imaserver backup command:
Console> imaserver backup “Password=mybackup_password”
Note: The mybackup_password command specifies a password for the compressed file
that contains the backup data. You must have the password when you attempt to
restore the backup.
4. Set the server to production mode, by entering the commands shown in Example 3-11 on
page 75.
These components are associated with a specific goal in a single place. You can create a
message hub for an application to organize the endpoints and policies that each application
uses.
3.6.1 Endpoints
Endpoints accept network requests so that clients can connect to the message hub through
MQTT or JMS. You must have a minimum of one endpoint per message hub. You can create
one endpoint for each port the message hub listens on.
Endpoints must have one or more connection policies that are applied to them to accept client
connections. Endpoints must have at least one messaging policy that is applied to them for a
connected client to be able to publish/subscribe.
There are two types of policies that can be defined on the message hub:
Connection policies: A connection policy filters any connection that is based on a rule. For
example, a connection policy might be set up to authorize users that are defined within a
particular group or groups to connect from a specific location or range of locations.
Messaging policies: A messaging policy authorizes a client or user to publish or subscribe
to a topic, or to send, receive, or browse messages on a queue. You can apply your
messaging policy to a topic or to a queue as part of the specification of the message
policy.
Note: Messaging policies that are created in the web UI can be used only within the
specified message hub. Messaging policies that are created in the CLI can be attached
to any endpoint in any message hub.
Figure 3-29 presents a simplified view of a message hub with its components and
cardinalities between components of a specific message hub.
Message Hub
1
1..*
1..* 1..*
Endpoint
1..*
1..* 1..*
0..1
Connection Messaging
Policy Security Policy
Profile
A connection policy can be applied to more than one endpoint that is defined in the same
message hub. For example, you can use a single connection policy to allow all clients from a
particular IP address range to connect. You can then restrict the access of different clients to
particular queues and topic strings by using a messaging policy.
Note: When specifying the Destination, you can use an asterisk (*) to specify all topic
strings or queues. You can also use variable substitution in the topic string or queue to
ensure that only specific user IDs, group IDs, client IDs, or client certificate common
names can access a topic. The variable for the user ID is ${UserID}.
When you create an endpoint, you can specify the following attributes:
Name
Enabled: True or False
IP address
Port
Protocol: JMS or MQTT
Maximum message size
Security profile
Connection policies
Messaging policies
The purpose of this message hub is to let developers rapidly integrate an application after
MessageSight is installed. The MessageSight Messaging Tester also uses this message hub
to test a network interface. See “3.4, “Overview of the MessageSight web UI” on page 57.
3. In the list of configured message hubs, you can see the DemoHub message hub, as shown
in Figure 3-31 on page 79.
4. Select DemoHub and click the pencil (edit) icon, as shown in Figure 3-32.
6. Select DemoMqttEndpoint and click the pencil (edit) icon to access its configuration, as
shown in Figure 3-34 on page 80.
Notice the listening port of the endpoint (1883) and the connection and messaging
policies. This endpoint does not provide any security control and it is configured to support
the MQTT protocol only.
7. Click Close to close the opening window.
8. Select the Messaging Polices tab from the DemoHub panel, as shown in Figure 3-36 on
page 81.
9. Select the DemoMessagingPolicy messaging policy and click the pencil (edit) icon.
10.A window opens, showing the configuration parameters of the DemoMessagingPolicy
messaging policy, as shown in Figure 3-37.
Notice the Destination (*) and the Authority (Publish and Subscribe) properties, which
indicate that publication and subscription can be done on any topic. JMS and MQTT
protocols have been selected, as well. Therefore, the defined messaging policy allows
access when the protocol is JMS or MQTT.
3.6.7 Configuring your first message hub using the MessageSight web UI
The creation of a message hub using the web UI is described in 5.2.1, “MessageSight basic
configuration” on page 109.
To configure a message hub and its components using the CLI, it is important to adhere to the
following order at creation time:
1. Message hubs
2. Connection policies
3. Messaging policies
4. Endpoints
The commands used to configure a message hub using the CLI are shown in Example 3-12.
Note: For details about the commands specific to message hubs, see Message hub
commands in the MessageSight IBM Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Refe
rence/MsgHubCmd/messagehubcommands.html?lang=en
The properties of the message hub that we create in this section are the same as those of the
DemoHub message hub, which was presented in 3.6.6, “The DemoHub message hub” on
page 78, with a few differences. The differences are the names of the hub components:
The name of the message hub we create using the CLI is PickmeupHub.
The name of the endpoint of the PickMeUpHub is PickmeupEndpoint.
The name of the connection policy associated with the PickMeUpEndpoint is
PickmeupConnPolicy.
The name of the messaging policy associated with the PickMeUpEndpoint is
PickmeupMsgPolicy.
Example 3-13 CLI commands to create the PickMeUp message hub and its components
Console>
Console>imaserver create MessageHub "Name=PickmeupHub" "Description=message hub
for the PickmeUp application"
The requested configuration change has completed successfully.
Console>
Console>imaserver create ConnectionPolicy "Name=PickmeupConnPolicy"
"Description=connection policy for the PickmeUp app" "Protocol=MQTT"
The requested configuration change has completed successfully.
Console>
Console>imaserver create MessagingPolicy "Name=PickmeupMsgPolicy"
"Description=messaging policy of the PickmeUp app" "DestinationType=Topic"
"Destination=*" "MaxMessages=5000" "ActionList=Publish,Subscribe"
"DisconnectedClientNotification=False" "Protocol=MQTT"
The requested configuration change has completed successfully.
Console>
Console>imaserver create Endpoint "Name=PickmeupEndpoint" "Description=endpoint of
Pickmeup message hub" "Port=16000" "Interface=all" "Protocol=MQTT"
"ConnectionPolicies=PickmeupConnPolicy" "MessagingPolicies=PickmeupMsgPolicy"
"MessageHub=PickmeupHub" "Enabled=True"
The requested configuration change has completed successfully.
Console>
Console>
Console> imaserver list MessageHub
DemoHub
PickmeupHub
Console>
The last command in Example 3-13 is imaserver list MessageHub, which is used to display
the list of message hubs that are configured on a MessageSight appliance. As you can see,
PickmeupHub is part of the list.
Connect the MessageSight web UI to confirm that the PickMeUp message hub has been
created, as shown in Figure 3-38.
Delete message hubs, and the message hub components, in the following order:
1. Endpoints
2. Messaging policies
3. Connection policies
4. Message hubs
In Example 3-14, the imaserver show command displays the configuration information of the
PickmeupEndpoint endpoint.
The bash script is shown in Example 3-15. The idea is to make the creation of message hubs
easier using a deployment script. This deployment script can be created, based on an XML or
JavaScript Object Notation (JSON) parameter file that can be implemented by a messaging
administrator.
ima_user=$1
ima_hostname=$2
commands_file="ima_commands.txt"
commands_execution_output="ima_commands_execution_output.txt"
#echo ima_hostname=$ima_hostname
Management
Configuration
System
Figure 3-39 Using the MessageSight SSH service to deploy a message hub configuration
To handle these challenges, a variety of topologies can be used. However, to accelerate the
design and implementation, the selected topology needs to be built on standard connectivity
patterns and components, to the greatest extent possible. The basic topology patterns that
are most relevant to the discussion of IBM MessageSight and the MQTT protocol are shown
in Figure 4-1.
This topology connects the devices to the enterprise integration layer through the edge
gateway. The edge gateway acts a hub or concentrator for devices to connect to, and
transports messages between the devices and enterprise integration layer. This topology is
ideal for systems with an unreliable or insecure network, or where the number of devices can
cause a performance slowdown if they are connected directly to the server in the enterprise
integration layer.
Table 4-1 lists the components of a client to edge to enterprise server topology.
Enterprise integration layer The server here acts as a central concentrator that remote
devices connect to. The following list reflects other activities
that the server supports:
Acts as an enterprise service bus for business
applications’ message exchange.
Capable of storing events and notifications for later
delivery, if connectivity was not available when first
attempted.
Capable of enforcing connection security by means of
Transport Layer Security (TSL)/Secure Sockets Layer
(SSL) to authenticate remote devices.
Capable of mediation for filtering and aggregating
messages, such as to reduce the volume of messages
traveling over the network.
Capable of event correlation, such as merging or mapping
an event or alarm between the devices and business
applications.
Table 4-2 Characteristics of systems benefited by client to edge server to enterprise server topology
Decision criteria Client to edge server to enterprise server
Data processing at remote location Moderate to extended (for example, filtering or data exchange
between devices at one physical location)
Device related
Available resources (for example, None to less resources available on the devices for extensions
processor or memory)
At remote locations, many devices have limited resources and
there is no room for extended integration functionality on these
devices. An edge gateway can implement these extensions and
reduce the impact on the devices.
Extensibility (for example, API or Almost closed device implementations with nearly zero access
connectivity options) to functions and data; proprietary device interfaces
Network related
Security of lower protocols Unsecured connectivity with the need for an additional security
layer on top
Today, many enterprises have already established a central enterprise integration facility and
monitoring for technical reasons. Nevertheless, data exchange with branch offices is still
handled in a batch-oriented manner with file transfer over unsecured and unreliable
connections in many cases. Changing these business processes from batch to reliable
connections and near real-time processing requires a paradigm shift. The Federated ESB
Pattern helps to extend the control of centrally managed integration processes to the edge.
Table 4-3 shows the topic used by different clients based on their roles.
Table 4-3 Application role and enumeration for a fan out broadcast pattern
Application Topic Action
Figure 4-4 on page 93 shows the live score application from the Australian open grand slam
event.
Table 4-4 on page 94 shows the topic used by different clients based on their roles.
In this scenario, the trash cans can publish pick up messages on the topic pickuptrash. The
pickup trucks have subscribed on the same topic and get notified when the trash cans are
getting full and they schedule a service pickup for this trash can.
Table 4-5 shows the topic used by different clients based on their role.
Table 4-5 Application role and enumeration for a fan out per device notification pattern
Application Action Topic
Passenger 1 Passenger 5
Subsc ribe - FF/1 011321/Noti fy
Subscribe - FF/10211 01/Notify
Figure 4-8 Push notifications to passengers for check-in, boarding, and baggage
This implementation shows five passengers who have an airline application installed on their
mobile phones. The application on the mobile phones subscribes to a unique notification
topic. Each notification topic is unique, because it contains the frequent flier ID of the
passenger and it follows the topic pattern as shown in Example 4-1.
Table 4-6 shows the various topics on which the applications on the passengers’ mobile
phones have subscribed.
Passenger 1 FF/1011101/Notify
Passenger 2 FF/1021101/Notify
Passenger 3 FF/1093101/Notify
Passenger 4 FF/1011321/Notify
Passenger 5 FF/1099321/Notify
If the airline back-end application has to notify passenger 3 for the web check-in, a message
must be published on the topic FF/1093101/Notify.
If the airline back-end application has to notify passenger 4 for the baggage claim, a message
must be published on the topic FF/1011321/Notify.
By publishing messages on unique topics, the airline company can notify their targeted
passengers.
Figure 4-9 Architecture of fan in per device request reply messaging pattern
Table 4-7 shows the topic used by different clients based on their roles.
Table 4-7 Application role and enumeration for a fan in per device request reply pattern
Application Publisher action Topic Subscriber action Application
Table 4-7 shows the topic strings for request and reply. The topic strings are unique for a
combination of different publishers and subscribers.
Passenger 1
Figure 4-10 Request reply messaging pattern between passengers’ mobile and back-end applications
This implementation shows five passengers who have an airline application installed on their
mobile phones. The application on the mobile phones subscribes to a unique reply topic and
publishes on a unique request topic. Each request and reply topic is unique because it
contains the frequent flier ID of the passenger and it follows the topic patterns shown in
Example 4-2 and Example 4-3.
Table 4-8 shows the various topics on which the applications on passengers’ mobile phones
can publish and subscribe messages.
Table 4-8 Topics for publish and subscribe from passenger application
Passenger Action Topic
application
Publish FF/1011101/QueryRequest
Passenger1
Subscribe FF/1011101/QueryResponse
Publish FF/1021101/QueryRequest
Passenger2
Subscribe FF/1021101/QueryResponse
Publish FF/1093101/QueryRequest
Passenger3
Subscribe FF/1093101/QueryResponse
Publish FF/1011321/QueryRequest
Passenger4
Subscribe FF/1011321/QueryResponse
Publish FF/1099321/QueryRequest
Passenger5
Subscribe FF/1099321/QueryResponse
Table 4-9 shows the various topics on which the airline back-end application will publish and
subscribe.
Table 4-9 Topics for publish and subscribe from airline backend application
Airline Action Topic
back-end
application
Subscribe FF/+/QueryRequest
Back-end
application Publish FF/1011101/QueryResponse
FF/1021101/QueryResponse
FF/1093101/QueryResponse
FF/1011321/QueryResponse
FF/1099321/QueryResponse
Table 4-10 shows the topic used by different clients based on their roles.
Table 4-10 Application role and enumeration for fan out per device request reply pattern
Application Publisher action Topic Subscriber action Application
Table 4-10 shows the topic strings for request and reply; the topic strings are unique for a
combination of a publisher and different subscribers.
Use case for a fan out per device request reply pattern
Smart connected cars are enabled with sensors that can sense a car crash and send
requests to emergency services. After the request is received by the emergency services, a
reply is sent to notify the connected car that the help is on its way. Figure 4-12 on page 101
shows the implementation of this pattern for request reply messaging between a connected
car and a multiple back-end emergency services application.
100 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 4-12 Smart connected car crash initiating emergency service request reply communication
This implementation shows three emergency services that have subscribed to requests from
connected cars:
Roadside assistance
Medical and ambulance assistance
Law enforcement and police assistance
The connected car sends a request to three emergency services and receives individual
responses from the emergency services applications. Table 4-11 shows the topics used by
the connected car to send a request and receive a reply from the emergency services
application.
Table 4-11 Topics for publish and subscribe from connected cars
Application Action Topic
Publish sc/CAL001/medicalRequest
sc/CAL001/policeRequest
sc/CAL001/roadsideRequest
Connected car
Subscribe sc/CAL001/medicalReply
sc/CAL001/policeReply
sc/CAL001/roadsideReply
Table 4-12 shows the topics used by the emergency services application to receive and reply
to a request from a connected car involved at the crash site.
A smart connected car with registration number CAL001 was involved in a crash. The
connected car will immediately send emergency service requests on the following topics:
sc/CAL001/medicalRequest
sc/CAL001/policeRequest
sc/CAL001/roadsideRequest
The emergency services have subscribed to emergency topics from all connected cars using
the topic pattern:
sc/+/medicalRequest
sc/+/policeRequest
sc/+/roadsideRequest
The emergency services application will reply to the connected car using the following topics,
which are also subscribed to by the connected car application:
sc/CAL001/medicalReply
sc/CAL001/policeReply
sc/CAL001/roadsideReply
Using these topics, the connected car and emergency services application can communicate
with each other.
102 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
QoS 1 messages are persistent. The message is stored on the IBM MessageSight server
until the message is sent to all the subscribers of the message. If the message subscriber
requested a QoS that requires an acknowledgment, the message is stored until the
acknowledgment is received.
In general, higher qualities of service are slower than lower qualities of service.
Note: A trial version of the key fob remote application is available at the following URL:
http://bit.ly/keyfobremote
Two online video tutorials related to the key fob application are also available. These
describe the MQTT application:
IBM MessageSight: Powering an MQTT application, which is accessible at this website:
http://bit.ly/keyfobvideo1
IBM MessageSight: Authenticating an MQTT application, which is accessible at this
website:
http://bit.ly/keyfobvideo2
The Car application models a real vehicle, with audio and text feedback when a control action
is made.
The Remote application is a virtual key fob, with the following options:
Start and stop the car
Lock and unlock the doors
Trigger the alarm
Honk the horn
Set the internal car temperature
Each application is built using the Eclipse Paho MQTT JavaScript client (see 1.2.4, “The
Eclipse Paho project” on page 9). Communication and synchronization occur with the MQTT
publish/subscribe messaging. The messaging server used by the MQTT clients to
communicate is MessageSight in the following ways:
The Car application indicates that Bob’s car is connected.
The Remote application indicates that the key fob is connected to Bob’s car.
The communication between the MQTT clients of the two applications (Car and Remote)
and the MessageSight server are based on MQTT over websockets.
106 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
mqtt over Websocket mqtt over Websocket
The first step that is required is to connect both the key fob remote and the Car applications,
as shown in Figure 5-2.
Figure 5-2 Connect the key fob remote and Car applications
The left pane represents the Remote application and the right pane represents the Car
application.
Chapter 5. IBM MessageSight and the key fob remote application 107
Enter the driver name (for example: Bob) in the Driver text field and click Connect. You will
access these two applications, as shown in Figure 5-3. Follow these steps:
1. The Remote application in the left pane.
2. The Car application on the right pane.
From here you can become familiar with the key fob, simulated by the Remote application,
to act on the car, simulated by the Car application.
You can perform the following actions on the car:
– Start and stop the car by using the Start and Stop buttons.
– Lock and unlock the doors by using the Lock and Unlock buttons.
– Trigger and stop the alarm by using the Alarm ON/Alarm OFF buttons.
– Honk the horn by using the Horn button.
– Set the internal temperature of the car by using the Climate Control selector.
Actions you execute with the Remote application display on the Car application, as shown in
Figure 5-4 on page 109. In this case, the Start engine button has been clicked on the
Remote application and the text, Engine started!, is displayed on the Car application.
108 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-4 Starting a car engine using a key fob remote
3. The remote is updated with the current status of the car. As shown in Figure 5-4, when the
engine has been started, the Start button of the remote becomes inactive, and the Stop
button becomes active. If several remotes are connected to the same car, the same
modification on the user interface is provided in the same time, on each remote.
First, and most importantly, we provide the basic configuration that is required to power a
simple MQTT application. Then, we add several security controls to this same configuration.
Chapter 5. IBM MessageSight and the key fob remote application 109
Figure 5-5 Accessing the Message Hubs configuration page
3. Click the plus sign (+) icon to add a new message hub, and a new window opens, as
shown in Figure 5-6.
4. Enter a name for the message hub (for example, AutoRemoteHub) and a description (for
example, Message hub for the key fob remote application), as shown in Figure 5-7.
5. Click Save. The AutoRemoteHub message hub is created, but, as shown in Figure 5-8 on
page 111, a warning symbol indicates that no endpoint has been configured on the hub.
110 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-8 Warning on a message hub that no endpoint is associated with the hub
6. Select AutoRemoteHub (click the pencil icon to edit), as shown in Figure 5-9.
Figure 5-9 AutoRemoteHub message that the hub is selected for addition
7. At this point, it is necessary to define at least one connection policy and one messaging
policy. From the Connection Policies tab of the message hub, click the plus sign (+) icon
to create a new connection policy, as shown in Figure 5-10.
Chapter 5. IBM MessageSight and the key fob remote application 111
8. In this scenario, we want to configure a basic message hub, so we define fairly open
policies. In the Add Connection Policy window, enter the following configuration
parameters, as shown in Figure 5-11, and click Save.
112 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
10.In the opening window, enter the following configuration parameters, as shown in
Figure 5-13, and click Save.
Chapter 5. IBM MessageSight and the key fob remote application 113
Each car subscribes to the control topic AutoRemote/<driver_name>, receives and
processes command messages that are published by a remote, and invokes the
appropriate function: start/stop engine, lock/unlock doors, and so on. Then, a car
publishes a status update back to the remote key fob. Status updates are published using
a JSON payload on the AutoRemote/<driver_name>/settings status topic, where
<driver_name> is the name (in lowercase) of the driver used at connection time, on both
the Remote and Car applications.
Each remote subscribes to the status topic AutoRemote/<driver_name>/settings, then
receives and processes status messages that are published by a car. A remote uses
status messages to set the state of its buttons (for example, the Start button is active or
inactive) and status display (for example, the Alarm ON/Alarm OFF display on the Alarm
button of the remote key fob).
11.The configuration of the AutoRemoteHub message hub finishes with the creation of an
endpoint. From the Endpoints tab of the message hub panel, click the plus sign (+) icon
to create a new messaging policy, as shown in Figure 5-14.
12.In the Add Endpoint window, enter the configuration parameters shown in Figure 5-15 on
page 115 and described:
– Name: Enter an endpoint name, for example, AutoRemoteEndpoint.
– Protocol: Select MQTT.
– Port: Enter the value 10000.
114 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-15 AutoRemoteEndpoint connectivity parameters
13.To attach the AutoRemoteConnection connection policy that was configured in Step 8 on
page 112, click the plus sign (+) icon in the Connection Policies table of the Add Endpoint
panel. Check Add to add the AutoRemoteConnection policy to the AutoRemoteEndpoint
endpoint, as shown in Figure 5-16.
Chapter 5. IBM MessageSight and the key fob remote application 115
Figure 5-17 Add messaging policy to the endpoint
18.Click the Return to Message Hubs link to return to the list of available Message Hubs on
your MessageSight appliance, as shown in Figure 5-19 on page 117.
116 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-19 Return to the list of message hubs
Figure 5-20 The newly created AutoRemoteHub is in the list of available message hubs
Chapter 5. IBM MessageSight and the key fob remote application 117
Figure 5-21 Connection parameters to test the key fob remote application
The following details describe the most valuable connection parameters for the two
applications:
– Driver name: Enter a driver name, for example, Bob. Use the same driver’s name for
the two applications (Remote and Car).
– Server: Enter the IP address or host name of your MessageSight appliance.
– Port: Enter the listening port of the AutoRemoteEndpoint endpoint, which was created
in Step 12 on page 114.
Note: The available actions on the Remote application are affected by the status of the
Car application. For instance, if the car (or Car application) is disconnected, the remote
(or Remote application) cannot operate. As soon as the car is connected to the
MessageSight server, the remote is able to connect to the car and send specific control
commands.
If you connect the Remote application before connecting the Car application, a message on
the Remote application window indicates that the remote cannot connect to the driver’s
car, as shown in Figure 5-22 on page 119.
118 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-22 Message that the remote cannot connect to the car
As soon as the car is connected, the remote is able to connect to the car, a shown in
Figure 5-23.
Figure 5-23 Message that the key fob remote is connected to the car
You can test the key fob remote application with your own MessageSight appliance, as
described in 5.1.2, “Testing the key fob remote application” on page 107.
Chapter 5. IBM MessageSight and the key fob remote application 119
5.3.1 Adding security controls to the key fob remote application
In this section, we discuss certain security controls that can be added for authentication and
authorization. We authenticate the clients at connection time and control the actions they can
execute when they are connected.
If you use authentication to secure your solution, consider complementing it with the
appropriate TLS. Using the correct TLS ensures that the user ID and passwords are not
transmitted in plain text.
Authentication is not the same as authorization. The authorization mechanism in the IBM
messaging appliance is achieved by using policies. These policies enable the messaging
user to connect to the IBM messaging appliance and use a messaging action, such as
publish or subscribe. Authentication validates that the messaging user is who they claim to
be, but it does not allow messaging users to connect or use any messaging actions.
The system administrator can create a messaging user account using the command-line
interface (CLI) or the MessageSight web UI.
Messaging users send and receive messages, but they cannot configure or maintain the IBM
messaging appliance.
120 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Each messaging user has a unique client ID. This client ID can be used in a connection policy
to allow or deny the user a connection to the IBM messaging appliance. The client ID can be
used in a messaging policy to control whether the user can publish or subscribe to a topic and
to control whether the user can send, receive, or browse a queue.
Messaging users can be added to groups. Adding users to a group can simplify
administration tasks. For example, you might want one set of users to publish to a particular
topic, and another set of users to subscribe to a particular topic. Instead of creating individual
messaging policies for each user, you can create a messaging group that is authorized to
publish to a topic. You can also create another messaging group that is authorized to
subscribe to a topic. Users can be added to the relevant messaging group. That group can
then be associated with the correct messaging policy.
Managing user authentication and authorization for the key fob remote
application
In this section, we configure MessageSight users and groups. Then, we update the
AutoRemoteHub endpoint, connection, and messaging policies to allow only the authenticated
users to connect and execute messaging actions on their own cars.
Our goal is to permit only those messaging users who belong to the new group that we create
to connect to the AutoRemoteHub endpoint.
Figure 5-24 Accessing the Messaging Users and Groups configuration page
3. Create a single messaging group by clicking the plus sign (+) icon in the Messaging
Group section of the page, as shown in Figure 5-25 on page 122.
Chapter 5. IBM MessageSight and the key fob remote application 121
Figure 5-25 Adding a messaging group
4. In the opening window, enter the parameters, as shown in Figure 5-26, and click Save.
5. Define the messaging users and attach them to the AutoRemoteGroup. To create a new
messaging user, click the plus sign (+) icon in the Messaging Users section of the page,
as shown in Figure 5-28 on page 123.
122 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-28 Adding a messaging user
6. In the Add User window, enter the configuration parameters, as shown in Figure 5-29.
The following details describe the messaging user parameters that need to be provided:
– User ID: Enter a name of the user, for example, Bob.
– Password: Enter a password, for example, Bob, that will be used by messaging user
Bob to connect to the AutoRemoteHub endpoint.
– Confirm Password: Confirm the password.
– Group Membership: Select AutoRemoteGroup, as shown in Figure 5-30 on
page 124.
Chapter 5. IBM MessageSight and the key fob remote application 123
Figure 5-30 Select a group membership
7. Based on Step 5 on page 122, create a second messaging user with the following
configuration parameters:
– User ID: The name of a user, for example, sally.
– Password: Enter a password, for example, sally, that will be used by messaging user
Sally to connect to the AutoRemoteHub endpoint.
– Confirm Password: Confirm the password.
– Group Membership: Select AutoRemoteGroup.
8. Based on step 5 on page 122, create a third messaging user with the following
configuration parameters:
– User ID: The name of a user. Enter a name, for example, other.
– Password: Enter a password. This password is used by Messaging User bob to
connect to the AutoRemoteHub endpoint. You can choose a password, for example,
other.
– Confirm Password: Confirm the password you have chosen, for example, other.
– Group Membership: Do not select any group for this third messaging user.
9. The three messaging users have been added to the messaging user list, as shown in
Figure 5-31.
124 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Note: The messaging user other has been created, but it does not belong to a
messaging group at this time.
To allow user authentication on the AutoRemoteHub message hub, execute the following steps:
1. Connect to the web UI of your MessageSight appliance using a system administrator or
messaging administrator account.
2. Select Messaging Message Hubsto access the message hub configuration panel, as
shown in Figure 5-5 on page 110.
3. Select the AutoRemoteHub message hub, and click the pencil icon to edit this hub, as
shown in Figure 5-32.
5. Because we want to restrict the connection to only the users of the AutoRemoteGroup
group, check the Group ID property, and enter the name of the messaging group
AutoRemoteGroup, as shown in Figure 5-34 on page 126.
Chapter 5. IBM MessageSight and the key fob remote application 125
Figure 5-34 Restrict the connection policy to messaging users who belong to a specific group
Note: Only the two group members of the messaging group AutoRemoteGroup, bob and
sally, can connect to the endpoint of the AutoRemoteHub message hub. Other users
cannot connect.
As described in Step 10 on page 113, remotes (or Remote applications) publish on the control
topic AutoRemote/<driver_name>, which cars (Car applications) subscribe to. Cars publish
responses back on the settings topic AutoRemote/<driver_name>/settings, which the
remotes receive. The name of the driver (<driver_name>) is used to connect a remote and a
car to the endpoint of the AutoRemoteHub message hub.
Setting a messaging policy for every user (in the case of this scenario, the driver) is not
possible. Fortunately, MessageSight supports the use of a few substitution variables at policy
creation, as described in 3.6.4, “Messaging policies” on page 77.
To substitute the user name used at connection time on the two topics
AutoRemote/<driver_name> and AutoRemote/<driver_name>/settings, we need to create
two messaging policies:
The first policy will be dedicated to the control topic.
The second policy will be dedicated to the settings topic.
126 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-35 Configuration of the AutoRemoteControl messaging policy
Chapter 5. IBM MessageSight and the key fob remote application 127
Figure 5-36 Configuration of the AutoRemoteSettings messaging policy
128 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-37 Messaging policies for control and settings created
6. Link the control and settings messaging policies to the endpoint of the AutoRemoteHub
message hub. From the Endpoints tab, select the AutoRemoteEndpoint endpoint and
click the pencil icon to edit the endpoint configuration, as shown in Figure 5-38.
7. In the Messaging Policies section of the Edit Endpoint window, click the plus sign (+) icon
to add the control and settings messaging policies, as shown in Figure 5-39.
Figure 5-39 Add the control and settings messaging policies to the AutoRemoteEndpoint endpoint
8. Select the two messaging policies that must be added, AutoRemoteControl and
AutoRemoteSettings, as shown in Figure 5-40 on page 130, and click Save.
Chapter 5. IBM MessageSight and the key fob remote application 129
Figure 5-40 Check AutoRemoteControl and AutoRemoteSettings
9. To remove the AutoRemoteMessaging messaging policy from the list of messaging policies
that must be enforced on the endpoint, select the AutoRemoteMessaging policy and
click the red cross icon, as shown in Figure 5-41.
Figure 5-41 Remove the AutoRemoteMessaging policy from the list of enforced policies
130 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-42 Final AutoRemoteEndpoint endpoint configuration
Figure 5-43 Connect the car to the MessageSight appliance with an authenticated user
Chapter 5. IBM MessageSight and the key fob remote application 131
Figure 5-44 User bob is authenticated and his car is connected
5. Connect the remote (Remote application) on Bob’s car with the user other, as shown in
Figure 5-45.
Figure 5-45 Connect the remote with an unauthenticated user named other
6. The user other cannot connect to the AutoRemoteHub message hub because that user
does not belong to the AutoRemoteGroup messaging group defined in the connection policy
AutoRemoteConnection of the hub’s endpoint, as shown in Figure 5-46 on page 133.
132 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-46 Remote cannot be connected to the AutoRemoteHub endpoint
7. Bob’s car is always connected. Now, we perform the same test, but with user sally, as
shown in Figure 5-47.
8. This time, the remote displays an error message, indicating that user sally cannot
connect to Bob’s car. The user sally can connect to the endpoint because she satisfies
the connection policy, but not the messaging policies defined at the endpoint level of the
AutoRemoteHub, as shown in Figure 5-48 on page 134. Therefore, sally cannot control
Bob’s car.
Chapter 5. IBM MessageSight and the key fob remote application 133
Figure 5-48 User sally cannot connect to Bob’s car
9. Bob’s car is always connected. For the last security test, we try to connect the key fob
remote with the user bob, as shown in Figure 5-49.
Figure 5-49 Try to connect Bob’s key fob remote to his car
10.This time the test is successful, the user bob is authenticated and his remote is allowed to
access his car to control it, as shown in Figure 5-50 on page 135.
134 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-50 Bob’s remote is connected to Bob’s car
11.To ensure that the remote can operate the controls on Bob’s car, click Start to start the car
engine. As shown in Figure 5-51, Bob’s car starts and the status of the car is started.
A security profile defines the security operations that are applied to a message flow. Each
security profile has an associated certificate profile that defines the server certificate to use.
Server certificates protect against impersonation, certifying that a public key belongs to a
specified entity.
Chapter 5. IBM MessageSight and the key fob remote application 135
Note: Information about how to configure an endpoint using SSL or TLS is at the IBM
Knowledge Center at the following URL:
http://www.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Securit
y/se00005_.html
TLS is configured within a message hub. Message hubs are associated with endpoints.
Endpoints control how clients can connect to the IBM messaging appliance. Each endpoint
can be associated with a security profile. The security profile determines the level of
encryption and the certificate profile that is used for an endpoint.
The anonymous SSL for the server certificate, key, and mutual authentication is supported on
MessageSight. You can specify a user name and password in the connect methods of the
Java Message Service (JMS), MQTT, and MQTT over websockets protocols to authenticate
users against the local user repository or an LDAP server.
Figure 5-52 on page 137 is a summary of an SSL and TLS handshake when mutual
authentication between an MQTT or JMS client and a MessageSight endpoint is configured
on a security profile.
136 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
IBM MessageSight
MQTT Client Device
1 « Hello » message
« Hello » response 2
Client Server
Certificate Server sends its digital certificate 3 Certificate
Server sends a « digital certificate request » message 4
« Hello done » message 5
6 Client verifies validity of Server’s digital certificate
Here is an explanation of the steps of the SSL handshake (Figure 5-52). Mutual
authentication is performed in this example:
1. The client sends a client hello message that lists the cryptographic capabilities of the
client (sorted in client preference order), such as the SSL version, the cipher suites
supported by the client, and the data compression methods supported by the client.
An example of a cipher suite is TLS_DH_RSA_WITH_DES_CBC_SHA: the key exchange
algorithm is DH_RSA (asymmetric). The cipher for data transmission during the session is
DES_CBC (symmetric). The hash algorithm is SHA.
The message also contains a 28-byte random number, known as RClientNum in the
following explanations.
2. The server responds with a server hello message that contains the cryptographic method
(cipher suite) and the data compression method selected by the server, the session ID,
and another random number (RServerNum). The client and the server must support at least
one common cryptographic method (cipher suite), or the handshake fails. The server
generally chooses the strongest common cipher suite.
3. The server sends its own digital certificate.
Chapter 5. IBM MessageSight and the key fob remote application 137
4. The server sends a digital certificate request message to the consumer application,
because it requires a digital certificate for client authentication. In this message, the server
sends a list of the types of digital certificates that are supported and the distinguished
names of acceptable certificate authorities.
5. The server sends a server hello done message and waits for a client response.
6. The client checks the server certificate for the following information:
– Certificate expiration.
– Server identity verification, which consists of a verification of the certificate’s signature
against a signed certificate in a keystore.
The client must have the digital certificate of the server in its keystore to validate the
server identity. However, it is not always possible to have every server certificate with
whom you want to communicate. A better solution for the server is to have its certificate
signed by a certificate authority (CA). This way, instead of the server sending its
certificate to each client, the client can validate a server certificate when presented
during SSL communication by verifying the CA certificate used to sign the server
certificate.
– Check the certification revocation list to see whether the certificate is no longer to be
trusted.
7. The client sends a digital certificate. If no suitable digital certificate is available, the client
sends a no digital certificate alert. This alert is only a warning, but the server
application can fail the session if client authentication is mandatory.
8. The server checks the client certificate in the same way that is described in Step 6.
9. The client sends a digital certificate verify message signed with its private key.
10.By verifying the signature of this digital certificate verify message, the server can
explicitly verify the ownership of the client digital certificate with the message that the
client is authenticated, if and only if the signature verification is successful. Signature
verification is performed using the public key of the client, which is included in the client
certificate.
11.The client sends a client key exchange message, encrypted with the public key of the
server.
This message contains the pre-master secret, a 46-byte random number (PMasterSecret)
used in the generation of the symmetric encryption keys and the message authentication
code (MAC) keys.
Note: An additional process to verify the server digital certificate is not necessary. If the
server does not have the private key that belongs to the digital certificate, it cannot
decrypt the pre-master secret and create the correct keys for the symmetric encryption
algorithm, and the handshake fails.
12.Both client and server use a series of cryptographic operations (using RClientNum,
RServerNum, and PMasterSecret) to convert the pre-master secret into a master secret key
from which all key material that is required for encryption and message authentication is
derived.
13.The client sends a change cipher spec message to make the server switch to the newly
negotiated cipher suite, referencing the newly created master secret key (shared between
the client and the server only). A change cipher spec message indicates that the contents
of subsequent SSL data sent will be encrypted.
14.The next message sent by the client (the finished message) is the first message
encrypted with this cipher method and the master secret key.
138 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
15.The server sends a change cipher spec message to confirm the use of the newly created
master secret key.
16.The next message sent by the server (the finished message) is encrypted using the
master secret key.
Communication between the client and server is now secured, and encrypted application
data can be sent and received by both the client device and the MessageSight server.
The security profile that is created in this chapter is not used in any scenario. The
configuration steps are provided to give you the details in case you need to implement such a
security configuration.
3. In the Certificate Profiles section of the Security Settings page, click the plus sign (+) icon
to create a new certificate profile, as shown in Figure 5-54 on page 140.
Chapter 5. IBM MessageSight and the key fob remote application 139
Figure 5-54 Adding a certificate profile
4. Enter the configuration parameters, as shown in Figure 5-55, and click Save.
140 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
6. Now, we can create a security profile that references the MyCertificateProfile
certificate profile that will include the elements used to authenticate the client from their
certificates.
Click the plus sign (+) icon in the Security Profiles section at the bottom of the Security
Settings page, as shown in Figure 5-57.
7. Enter the configuration parameters, as shown in Figure 5-58, and click Save.
Chapter 5. IBM MessageSight and the key fob remote application 141
The following details describe the parameters that can be provided or selected:
– Name: Enter a name, for example, MySecurityProfile.
– Minimum Protocol Method: Select one of the following values:
• SSLv3
• TLSv1 (TLS1.0)
• TLSv1.1
• TLSv1.2
– Ciphers: Select one of the following values:
• Best: Select the most secure cipher supported by the server and the client.
• Fast: Select the fastest high security cipher supported by the server and the client.
• Medium: Select the fastest medium or high security cipher supported by the client.
• Client Certificate Authentication: Check the box if you want to enable client
authentication based on SSL or TLS. In our case, we check the box because we
want to implement mutual authentication on the security profile.
Note: At this step, if you do not want to process mutual authentication but 1-way
SSL/TLS only, do not check the Client Certificate Authentication box. Then, save
your security profile and go directly to Step 11 on page 143 to discover how to
associate your security profile to an endpoint.
• Use Client Cipher’s Ciphers: Choose whether to allow the client to determine the
cipher suite to use when connecting.
• Use Password Authentication: Choose whether to require a valid user ID and
password when connecting.
• Certificate Profile: Select a certificate profile from the list of available certificate
profiles. In our example, we select MyCertificateProfile.
• LTPA Profile: Do not select any value. For more information about the client
authentication mechanism, refer to the IBM Knowledge Center website at the
following URL:
http://www.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/S
ecurity/se00013_.html?lang=en
8. Provide the CA certificate of the client devices, by selecting the MySecurityProfile
security profile and then selecting Other Actions Trusted Certificates, as shown in
Figure 5-59.
142 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
9. The opening window is the user interface to use for defining a list of trusted certificates.
Click Browse to select a client certificate from your file system, as shown in Figure 5-60.
10.Click Upload to upload the selected certificate from the list of MessageSight trusted
certificates, as shown in Figure 5-61, and click Close.
Note: The certificate added in the truststore must be an X.509 certificate and signed by
a certificate authority (CA) trusted by MessageSight. A self-signed certificate is not
accepted as a trusted certificate.
Chapter 5. IBM MessageSight and the key fob remote application 143
Figure 5-62 Attaching a security policy to an endpoint
Revoking certificates
To revoke a certificate, you must replace it with a new certificate on the MessageSight
appliance. Delete the certificate profile of the compromised certificate, and create a certificate
profile with a new certificate. Then, associate the new certificate profile with the correct
security policy.
The FIPS 140-2 standard requires the use of strong cryptographic algorithms. FIPS 140-2
also specifies the requirements for hashing algorithms for use in protecting packets against
modification in transit. Over time, analysts develop attacks against existing encryption and
hashing algorithms. New algorithms are adopted to resist those attacks. FIPS 140-2 is
periodically updated to include these changes. For more information about FIPS, see the
following website:
http://www.itl.nist.gov/fipspubs/
Note: You can have the IBM messaging appliance configured to provide FIPS 140-2
support. Changes to the FIPS 140-2 setting require a restart of the MessageSight server.
To provide FIPS 140-2 support on a MessageSight appliance, execute the following steps:
1. Connect to the web UI of your MessageSight appliance using a system administrator
account.
2. Select Appliance Security Settingsto access the message hub configuration panel,
as shown in Figure 5-63 on page 145.
144 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 5-63 Accessing security settings
3. In the System-wide Security Settings section of the Security Settings page, check Use
FIPS 140-2 profile for secure messaging communications. A window opens, indicating
that a restart of the MessageSight server is required for the modification to take effect, as
shown in Figure 5-64.
Figure 5-64 Changing the FIPS setting requires a restart of the MessageSight Server
4. Click Set and Restart to provide FIPS support on your MessageSight appliance.
Chapter 5. IBM MessageSight and the key fob remote application 145
146 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
6
Throughout this chapter, we refer to the business problem of Company A and the solution as
provided by the PickMeUp application.
Figure 6-1 on page 149 visually captures the functional requirements for PickMeUp for use at
Company A.
148 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Send picture
*include*
*include*
Play Media Content *include*
Chat Send voice
Last Pickmeup
Requests
Accept Pickmeup
Driver Request
*include*
Login
Authenticate
Passenger
Submit Pickmeup
Request
Make Payment
Pickmeup server
Payment system
Figure 6-1 Diagram of the functional requirements for PickMeUp for use by Company A
Actors
There are five main actors in the context of PickMeUp in our scenario for Company A:
Driver: Taxi driver at Company A
Passenger: Customer of Company A
IBM MessageSight server: MessageSight messaging server
Payment system: Payment system that processes payments for taxi rides
PickMeUp back end: Server side of PickMeUp
Note: In the mobile app, the driver signs in only with a user name (no password is
required) to connect to the MessageSight server.
Note: The app lists all of the local, pending PickMeUp requests that are currently in the
system.
150 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Company A passenger actor
The requirements of the passenger actor are listed:
Login
To connect to the MessageSight server, the passenger logs in to the PickMeUp passenger
app, using the registered user name for authentication.
Note: In the mobile app, the driver signs in only with a user name (no password is
required) to connect to the MessageSight server.
152 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Capacity and performance
The PickMeUp system must have the ability to handle a high number of requests and
messages.
Given the need for a near real-time experience, the messages must be transferred and
processed fast, with low latency between endpoints.
Availability
The system must be available 24 hours/day, seven days/week.
Security
Every connection and transaction between endpoints must be secured.
Figure 6-2 on page 154 captures the overall architecture of the PickMeUp system and briefly
describes the anticipated software and hardware components that are required to implement
the solution in the scope of this book.
MQTT
MQTT
Passenger
Passenger app
IBM MessageSight
MQTT
Driver
Driver app
Note: Native mobile application development has been chosen to take advantage of
OS-specific features and, because there are three versions of the app on various
platforms, to demonstrate the abundance of the MQTT clients available for developers
to use in the solutions.
Driver app
The PickMeUp driver app runs on the driver’s mobile device. The target platforms for the
app are iOS and mobile web with HTML5 enabled.
Note: To quickly try the application without any installation, having an HTML5 version of
the driver app is critical for running the app directly on mobile browsers that support
HTML5.
154 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
PickMeUp back end
The PickMeUp back end is designed to act as an interface to seamlessly simulate the
payment process. The back end is also responsible for cleaning up the abundant data that
is stored on the MessageSight server.
Note: To simplify development, deployment, and hosting, the back end is built using
Node.js and the MQTT node library on top of the IBM Bluemix™ cloud environment.
IBM MessageSight
The MessageSight appliance functions as the messaging server for the solution.
MQTT
MQTT is used as the messaging protocol over the MessageSight server to provide
real-time experience and a high messaging capacity.
Referential architecture
This section provides a typical architecture overview to use as a referential architecture for
building a real mobile application with MQTT and MessageSight. Figure 6-3 on page 156 is
the architecture overview diagram for such a use case.
http(s)
MQTT
Passenger
JMS MQTT
IBM MessageSight
LDAP
DMZ
Enterprise Resource
LDAP Planning System
Driver
Driver app
Figure 6-3 Referential architecture overview for a mobile application using MQTT and MessageSight
Security considerations
In this section, we deal with improving the security level of the PickMeUp solution.
The MessageSight appliance plays a prominent role in the PickMeUp solution, because it
(MessageSight) acts as a hub between the various actors of the solution. Therefore,
MessageSight is a key component in terms of security.
156 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
A basic PickMeUpHub message hub configuration is described in “Create a basic message hub
using the CLI” on page 82.
The following security improvements can be enhanced for the driver app and for drivers:
To ensure that a driver who connects to the system is using the official driver app, mutual
authentication is carried out. This application can be reserved for drivers of a specific taxi
company.
Mutual authentication can be based on Secure Shell (SSL) (v3) or Transport Layer
Security (TLS) (v1.0, v1.1, or v1.2). Both SSL and TLS are supported on MessageSight
when mutual authentication needs to be implemented.
Configuration of mutual authentication on MessageSight is described in “Configuring
mutual authentication on MessageSight” on page 139.
Authentication of drivers that use a user name and password. After the driver app has
been authenticated, the driver needs to be authenticated at connection time. The user
name and password capabilities of MQTT can be used, because MessageSight can rely
on an LDAP server and perform the required security enforcement. The drivers, as
messaging users, can also be configured directly on MessageSight and can be associated
to user groups.
Note: Configuration details are available in Configuring an external LDAP server in the
IBM MessageSight Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/A
dministering/ad00371_.html?lang=en
A MessageSight endpoint with a dedicated security profile and a connection policy can be
configured to support mutual authentication of the driver app and authentication of the
drivers.
Another important aspect of security is authorization. The list of driver topics for both
publications and subscriptions is in 7.4.1, “Driver app topics” on page 186. Based on these
topics defined for the PickMeUp messaging use case, it is possible to configure messaging
policies to enforce them on MessageSight, after the drivers are connected. The goal here is
to confirm that the drivers use a dedicated list of topics for both publish and subscribe actions.
Driver messaging policies can be configured with the destinations and authorities shown in
Table 6-1 on page 158.
Note: The destination property uses the substitution variable ${ClientId}. Details about
substitution variables are available in 3.6.4, “Messaging policies” on page 77.
Figure 6-4 summarizes a possible MessageSight endpoint configuration for enhancing the
security of the PickMeUp solution for drivers.
PickmeUpHub
Drivers
endpoint
Messaging
Connection Policies
Policy
MQTT - Publish
Security Authentication of pickmeup/drivers/{$ClientId}
Profile drivers based on pickmeup/drivers/{$ClientId}/location
username and pickmeup/requests/*
Mutual Authentication
password (mqtt) pickmeup/passengers/*/inbox
of drivers application
pickmeup/passengers/*/chat
MQTT - Subscribe
pickmeup/drivers/{$ClientId}/inbox
pickmeup/requests/*
pickmeup/passengers/*
pickmeup/passengers/*/picture
pickmeup/passengers/*/location
pickmeup/drivers/${ClientId}/chat
158 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Improve the security level of the passenger app
In this section, we present a solution for improving the security level of the PickMeUp solution
from a passenger perspective.
Passengers do not need to be authenticated when they request a ride. The only stage when
passengers need to be authenticated is when payment is being made. Therefore, we need
two endpoints that are dedicated to passengers on MessageSight:
The first endpoint must provide confidentiality between the passenger and driver.
Therefore, 1-way SSL or TLS is required at connection time on this endpoint. The same
security level can also be used during the pairing, approaching, and riding stages.
The second endpoint is dedicated to payment. To connect to this endpoint, passengers
first authenticate to a web token service and then use the delivered token to authenticate
through a configured MessageSight payment endpoint.
To authenticate passengers, MessageSight can rely on LTPA tokens.
Another important aspect of security is authorization. The list of passenger topics for both
publications and subscriptions is in 7.4.2, “Passenger app topics” on page 186. Based on
these topics, as defined for the PickMeUp messaging use case, it is possible to configure
messaging policies to enforce them on MessageSight, after a passenger is connected. The
goal is to confirm that a passenger is using a dedicated list of topics for both publish and
subscribe actions.
Passenger messaging policies can be configured with the destinations and authorities shown
in Table 6-2.
Table 6-2 Destination and authority of MessageSight messaging policies for passengers
Topic defined at design time Destination Authority
Note: Destination properties use the substitution variable ${ClientId}. Details about
substitution variables are available in 3.6.4, “Messaging policies” on page 77.
Figure 6-5 on page 160 summarizes a possible MessageSight endpoint configuration for
enhancing the security of the PickMeUp solution for passengers at the connecting, pairing,
approaching, and riding stages.
Passengers
Endpoint for driving
Connection
Policy
Messaging
Security Policies
Profile
MQTT - Publish
pickmeup/passengers/{$ClientId}
1-way TLS between pickmeup/requests/{$ClientId}
passengers and endpoint pickmeup/passengers/{$ClientId}/picture
pickmeup/passengers/{$ClientId}/location
pickmeup/drivers/*/chat
MQTT - Subscribe
pickmeup/passengers/{$ClientId}/inbox
pickmeup/drivers/*
pickmeup/drivers/*/picture
pickmeup/passengers/{$ClientId}/chat
pickmeup/drivers/*/location
Figure 6-6 on page 161 summarizes a possible MessageSight endpoint configuration for
enhancing the security of the PickMeUp solution for passengers at the payment stage.
160 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
PickmeUpHub
Passengers
Endpoint for payment
Connection
Policy
Messaging
Security Policies
Profile
A MessageSight endpoint with a dedicated security profile and messaging policies can be
configured to support mutual authentication and authorization of the back-end application.
The back-end messaging policies can be configured with the destinations and authorities
shown in Table 6-3.
Table 6-3 Destination and authority of MessageSight messaging policies for the back-end application
Topic defined at design time Destination Authority
PickmeUpHub
Back-end
endpoint
Connection
Policy
Messaging
Security Policies
Profile
Mutual Authentication MQTT - Publish
of back-end application pickmeup/drivers/*/inbox
pickmeup/passengers/*/inbox
pickmeup/passengers/*/location
pickmeup/passengers/*
pickmeup/passengers/*/picture
MQTT - Subscribe
pickmeup/payments
Figure 6-8 on page 163 depicts the complete, secured PickMeUp solution.
162 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
LTPA token
request
Driver Passenger Passengers WebSphere
HTTP/TLS
Application
mqtt/TLS
Server
1-way TLS
mqtt/TLS
Passengers 1-way TLS Passengers
authentication
endpoint for
driving
Passengers
Mutual Authentication
+ endpoint LDAP
Driver authentication MQTT for payment
(username/password)
Broker
mqtt/TLS Drivers
2-way TLS
endpoint
Drivers
pickmeupHub
ldap(s)
Back end
Figure 6-8 Complete, secured PickMeUp solution
We address the business problem and the requirements in the following areas:
Connecting
Pairing
Approaching
Riding
Processing payment
For simplification, and so that readers can quickly build and run the code, the PickMeUp mobile
application developed within the scope of this book does not require the level of security
described here for connecting to the MessageSight server. With that consideration, the
passenger and driver only need to enter their user name for the app to be connected with the
server.
Figure 6-9 shows the UI on the passenger and driver apps during this connection stage.
Figure 6-9 Passenger app and driver app UI during the connecting stage
164 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
6.3.2 Scenario 2: Pairing
Scenario 2 describes the pairing process between the PickMeUp driver app and passenger
app:
1. The passenger submits a PickMeUp request using the passenger app. The request is
transformed to an MQTT message, which includes the current location of the passenger
and the publication to a specific topic name on the MessageSight server.
2. The driver receives the PickMeUp request using the driver app, which subscribes to the
matching MQTT topic name on the MessageSight server. The request to the driver is in
the form of an MQTT message. When delivered to the driver app, the message displays
in a list of requests and on a map of the passenger’s physical location.
3. The driver accepts a request in the list. The acceptance is transformed to an MQTT
message that includes information about the passenger and publication to the specific
topic name on the MessageSight server on which the passenger app subscribes.
4. The passenger is notified that a driver has been located and the passenger is asked to
continue.
5. The driver app and the passenger app are both switched to the next stage.
Figure 6-10 shows the UI of the passenger app and the driver app in the pairing scenario.
Figure 6-10 Passenger app and driver app UI during the pairing stage (© OpenStreetMap contributors)
Figure 6-11 shows the UI of the passenger app during the approaching stage.
Figure 6-12 on page 167 shows the UI of the driver app in the approaching scenario.
166 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 6-12 Driver app UI during the approaching stage (© OpenStreetMap contributors)
Figure 6-13 on page 168 shows the UI of the driver app in the riding stage.
168 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
4. The PickMeUp back end receives the message, parses the payment details, and then
sends notification to the passenger app and driver app indicating that payment is
completed. The notification is in a form of an MQTT message and publication to specific
topic names that are associated with the passenger and driver on which the passenger
app and driver app are subscribing.
Note: In an actual scenario, this step might differ. For example, the PickMeUp back end
receives the message, parses the payment details, and then interacts with other
payment subsystems to perform the payment. After the payment transaction is
complete, the back end sends a notification to the passenger app and driver app that
payment is completed. The notification is in the form of an MQTT message and
publication to specific topic names that are associated with the passenger and driver on
which the passenger app and driver app are subscribing.
5. The passenger app and driver app receive a notification that the transaction is complete.
The notification originates from the PickMeUp back end, which interacts with the Payment
system. All messages and notifications are transferred to endpoints by MessageSight.
Figure 6-14 shows the UI of the driver app and the passenger app in the payment
scenario.
Figure 6-14 Passenger app UI and driver app UI during the payment scenario (© OpenStreetMap contributors)
With the transaction complete, the PickMeUp back end performs a cleanup of MessageSight
against the completed transaction to ensure that no extraneous data is left on MessageSight.
The passenger app and driver app display the main UI, from which a new PickMeUp cycle can
be started.
The transport protocol that is implemented on the PickMeUp solution is MQTT, an extremely
lightweight publish/subscribe messaging protocol.
The MQTT topics and messages that are implemented in the solution are detailed in this
chapter. We present the stages of the PickMeUp scenario, the actors involved, and the topics
and messages used for both publications and subscriptions.
Other considerations, such as quality of service (QoS) level, session type for each
subscription (durable or non-durable), and publication type (retained or not retained), are also
described in this chapter.
172 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Passengers
Drivers mqtt
MQTT Broker
Back end
Note: Actors in the PickMeUp solution exchange information through MessageSight (the
MQTT broker), using the MQTT protocol.
For each stage, we describe the quality of service (QoS) level used for publications, the
publication type (retained or not retained), and the session type for subscriptions (durable or
non-durable). See “Quality of service (QoS) levels and flow” on page 236 for descriptions of
the QoS levels.
7.3.1 Connecting
At connection time, three actors connect to the MessageSight server:
The driver, using the HTML5 PickMeUp driver app.
The passenger, using either the iOS or Android PickMeUp passenger app.
The back end, using a dedicated application that is able to integrate with a payment
system. The back-end application is based on Node.js.
Each driver, passenger, and the back-end application connect to MessageSight using a
unique client identifier. Details about the client identifier are in 6.2, “PickMeUp architecture for
real-life use” on page 153.
At the end of the connecting stage, the driver app, passenger app, and back-end application
are all connected to the MessageSight server.
The following details refer to the JSON connection message shown in Example 7-1:
name: The name of the driver or passenger, as viewed by the passenger or driver
connectionTime: The connection time in milliseconds, since January,1st 1970
This JSON message is published as a retained message, using QoS level 0. Each passenger
app and driver app publishes the JSON connection message on one of the following
dedicated topics:
Pickmeup/passengers/passengerId for the passenger app
Pickmeup/drivers/driverId for the driver app
174 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Note: In this chapter, passengerId is the client identifier used by the MQTT client of the
passenger app to connect to MessageSight. Similarly, driverId is the client identifier used
by the MQTT client of the driver app to connect to MessageSight.
Note: The MQTT protocol defines a client identifier (client ID) that uniquely identifies a
client on a network. In simple terms, when connecting to a messaging server, a client
needs to specify a unique string that is not used currently and will not be used by any other
client that will connect to the MQTT server.
Also, to perform the MQTT client connection, both the driver app and the passenger app use
the last will and testament property provided by the MQTT protocol, when connecting to
MessageSight.
Note: When a client app connects to a messaging server, such as MessageSight, it (the
client app) can define a topic and a message that will be published automatically if it
unexpectedly disconnects. This is called the last will and testament (LWT).
In the case of the PickMeUp solution, the last will and testament message used by both the
driver app and the passenger app is an empty message. This empty message is associated
with last will and testament topics, which differ for each driver app and passenger app:
Pickmeup/passengers/passengerId for the passenger app
Pickmeup/drivers/driverId for the driver app
Therefore, if the passenger app or driver app is unexpectedly disconnected from the
messaging server, the JSON connection message is erased from the MQTT broker
(MessageSight) for both the passenger and driver.
When there is a clean disconnection (when the DISCONNECT method (provided by the
MQTT protocol) is used to disconnect an MQTT client from an MQTT broker), the two JSON
connection messages have to be erased before the passenger app and driver app are
disconnected.
Each driver also publishes a picture when connecting to the PickMeUp driver app. Pictures
are published using a retained message on the following topic:
Pickmeup/drivers/driverId/picture.
The JSON message used to send a picture is shown in Example 7-2, where base64Binary is
the binary content of an image encoded in Base64.
The session flag used for subscriptions that use inbox topics is false, which means that the
subscription is durable over time. In this case, when a driver or passenger is temporarily
disconnected from the MQTT broker because of a network failure, the driver application and
the passenger application do not lose any inbox messages that are published on the inbox
topics.
A summary of the actors, connections (connect), publications (pub), and subscriptions (sub)
at connection time is shown in Figure 7-2.
• Retained: yes
• QoS: 0 pickmeup/passengers/<passengerId>
Last Will & Testament: pub
• topic: pickmeup/drivers/<driverId> {
"name": “<passengersName>",
• payload: empty
connect }
"connectionTime": <time>
• Retained: yes
pickmeup/drivers/<driverId> • QoS: 0
pub pickmeup/passengers/<passengerId>/inbox
sub
{
"name": “<driversName>", • QoS: 2
"connectionTime": <time>
}
• Retained: yes
• QoS: 0
pickmeup/drivers/<driverId>/picture
pub MQTT Broker
{
“url": “data:image/png;base64,<base64_binary>“ connect
}
pickmeup/drivers/<driverId>/inbox • QoS: 2
sub
Back end
Figure 7-2 Summary of the actors, connections (connect), publications (pub), and subscriptions (sub) at connection time
7.3.2 Pairing
At pairing time, two actors interact with each other:
Drivers by using the HTML5 PickMeUp driver app
Passengers by using either the iOS or the Android PickMeUp passenger app
The pairing stage consists of linking an available driver with a passenger who is requesting a
ride.
176 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Passenger publications during the pairing stage
A passenger requests a ride by publishing a specific JSON request message on the request
topic Pickmeup/requests/passengerId. An example of a JSON request message is shown in
Example 7-3.
The JSON request message includes the passenger name and position in longitude and
latitude. This message is published as a retained message. In this way, newly connected
drivers can see passenger requests that are pending. The QoS published that the request
message is at level 1, acknowledging that the message has been delivered to connected
drivers.
The driver app displays a list of passenger requests, including request messages and topics,
and passenger names, positions, and identifiers.
The JSON confirmation message includes an acceptance status that is a static value
(accept) and the driver’s identifier and position in longitude and latitude.
Based on the driver identifier, the passenger app subscribes to the following two topics to
obtain the name and position of the driver who accepted the ride, including a picture of the
driver:
Pickmeup/drivers/driverId: A message published on this topic contains the name and
position of the driver who is connected to MessageSight and using driverId as a client
identifier.
Pickmeup/drivers/driverId/picture: A message published on this topic contains the
picture of the driver who is connected to MessageSight and using driverId as a client
identifier.
A summary of actors, publications (pub), and subscriptions (sub) at pairing time is shown in
Figure 7-3 on page 178.
• Retained: yes
Drivers Passengers • QoS: 1 pickmeup/requests/<passengerId>
pub
{
"name": “<passengersName>",
“lon": <longitude>,
“lat": <latitude>
}
pickmeup/drivers/<driverId>
sub
pickmeup/requests/+ sub
pickmeup/drivers/<driverId>/picture
sub
pickmeup/requests/<passengerId>
pub
• Retained: yes
• QoS: 0
• payload: empty
Back end
Figure 7-3 Summary of the actors, publications (pub), and subscriptions (sub) at pairing time
Note: The back-end system does not participate in the pairing stage. Nevertheless, it is
always connected to MessageSight from the connecting stage through to the payment
stage.
178 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
7.3.3 Approaching
During the approaching stage, the PickMeUp solution provides a chat system between the
driver app and the passenger app, allowing both people to exchange information.
The aim of this chat is to facilitate the approach for the driver and to reduce waiting time for
the passenger. The chat allows the exchange of text and audio data.
The positioning message provides the longitude and latitude of the driver’s position. The
positioning message is published as a retained message, so if the passenger app has to
reconnect, it obtains the latest driver’s position.
Pickmeup/passengers/passengerId/chat: The driver app publishes text or audio data to
the passenger chat topic. Chat messages can include text or audio data. An example chat
message that includes text is shown in Example 7-6.
An example of a chat message that includes audio data is shown in Example 7-7.
The audio data is encoded in Base64 before being included in the JSON chat message.
Chat messages are published as non-retained messages.
During the approaching stage, the passenger app publishes a retained message
corresponding to a passenger picture, using QoS level 0. This message is published on topic
Pickmeup/passengers/passengerId/picture. The JSON message used to publish a picture is
shown in Example 7-2 on page 175.
180 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
• Retained: yes
Drivers Passengers • QoS: 0 pickmeup/passengers/<passengerId>/picture
pub
{
“url": “data:image/png;base64,<base64_binary>“
}
pickmeup/passengers/<passengerId>/chat
sub
pickmeup/drivers/<driverId>/location
sub
pickmeup/passengers/<passengerId> pickmeup/drivers/<driverId>/chat
sub { pub
pickmeup/passengers/<passengerId>/picture cf. driver side • Retained: no
sub } • QoS: 0
sub
pickmeup/passengers/<passengerId>/location pickmeup/passengers/<passengerId>/location
{
pub
“lon”:<longitude>, • Retained: yes
pickmeup/drivers/<driverId>/chat “lat”: <latitude> • QoS: 0
sub }
pickmeup/passengers/<passengerId>/chat
pub
• Retained: no MQTT Broker
• QoS: 0
{
“format”:”text”,
“data”:”<text>”
}
or {
“format”:”data:audio/wav;base64”,
“data”:”<base64_encoded_data>”
}
pickmeup/drivers/<driverId>/location
pub
• Retained: yes
• QoS: 0
{
“lon”:<longitude>,
“lat”:<latitude>
} Back end
Figure 7-4 Summary of the actors, publications (pub), and subscriptions (sub) at approaching time
7.3.4 Riding
The riding stage starts after the approaching stage is completed. This means that a driver
and a passenger are located at the same position.
An example of the start trip message is provided in Example 7-8 on page 181.
When the trip is completed, the driver app publishes a message on a passenger inbox topic,
Pickmeup/passengers/passengerId/inbox, indicating that the trip has ended. We call this
message the trip-end message.
The driver app embeds specific algorithms, which are used to calculate the cost of the trip
based on the time and distance of this trip. An example is shown in Example 9-7 on
page 212.
After the trip cost is calculated, the trip-end message is sent to the passenger app to notify the
passenger of the cost, so that the passenger can proceed with payment.
A summary of the actors, publications (pub), and subscriptions (sub) at riding time is shown in
Figure 7-5 on page 183.
182 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Drivers Passengers
• Retained: no {
• QoS: 2 "type": "tripStart"
}
pickmeup/passengers/<passengerId>/inbox
pub
Back end
Figure 7-5 Summary of the actors, publications (pubs), and subscriptions (sub) at riding time
7.3.5 Payment
The payment stage starts after the trip ends. The payment is performed by a passenger using
the passenger app. The back-end system is part of the payment process.
Note: The message must be stored locally on the passenger app, until the passenger app
receives confirmation that the payment order message was published by MessageSight.
Example 7-10 presents an example of a payment order message, which must be published
as a not-retained message.
A payment order message uses a JSON format. A payment order contains the driver’s and
passenger’s identifiers. It also contains the cost of the trip, the rating (a one-to-five star rating
is used) and the tip given by a passenger.
The subscription of the back-end system on the payment topic must be done using a QoS
level 2 to receive messages on the payment topic at the QoS at which they are published,
which is QoS level 2.
Note: A publisher is responsible for determining the maximum QoS at which a message
can be delivered, but a subscriber is able to downgrade the QoS to one more suitable for
its use. The QoS of a message is never upgraded.
For example, if a client has a QoS level 1 subscription to a particular topic, a QoS level 0
message published to that topic is delivered to the client at QoS level 0. A QoS level 2
message published to the same topic is downgraded to QoS level 1 for delivery to the
client.
The back-end application publishes a trip processed message, which is based on a JSON
format, as shown in Example 7-11.
The trip processed message type is tripProcessed. It contains the tip amount and the driver’s
rating that was entered by the current passenger.
The trip processed message is published as non-retained using QoS level 2 on the following
inbox topics:
Pickmeup/drivers/driverId/inbox
Pickmeup/passengers/passengerId/inbox
The driver app and passenger app can use this message to confirm that the trip payment is
processed.
184 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
The back-end system also proceeds to clean up the two passenger retained messages: the
positioning and the picture message. To clean up these retained messages, an empty
message is published on the following topics using QoS level 0:
Pickmeup/passengers/passengerId/picture: This topic corresponds to the passenger
picture that was uploaded at the beginning of the approaching stage.
Pickmeup/passengers/passengerId/location: This topic corresponds to the passenger’s
last position at the end of the approaching stage.
A summary of the actors, publications (pub), and subscriptions (sub) at payment time is
shown in Figure 7-6.
• Retained: no
Drivers Passengers • QoS: 2 pickmeup/payments
pub
{
“driverId": “<driverId>“,
“passengerId”: “<passengerId>”,
”cost”:<cost>,
”rating”:<rating>,
“tip”:<tip>
}
pickmeup/payments • QoS: 2
MQTT Broker sub
pickmeup/drivers/<driverId>/inbox
pickmeup/passengers/<passengerId>/inbox
pub
• Retained: no {
• Retained: yes • QoS: 2 “type": “tripProcessed“,
• QoS: 0 “tip": <tip>,
”rating”:<rating>
• payload: empty
pub }
pickmeup/passengers/<passengerId>/location
• Retained: yes
• QoS: 0 pickmeup/passengers/<passengerId>/picture
• payload: empty Back end
pub
Figure 7-6 Summary of the actors, publications (pub), and subscriptions (sub) at payment time
Driver publications
A summary of driver app publications is shown in Table 7-1.
Pickmeup/drivers/driverId Yes 0
Pickmeup/requests/passengerId Yes 0
Pickmeup/passengers/passengerId/inbox No 1,2
Pickmeup/passengers/passengerId/chat No 0
Pickmeup/drivers/driverId/location Yes 0
Driver subscriptions
A summary of driver app subscriptions is shown in Table 7-2.
Passenger publications
A summary of passenger app publications is shown in Table 7-3 on page 186.
Pickmeup/passengers/passengerId Yes 0
Pickmeup/requests/passengerId No 1
Pickmeup/passengers/passengerId/picture Yes 0
Pickmeup/passengers/passengerId/location Yes 0
Pickmeup/drivers/driverId/chat No 0
Pickmeup/payments No 2
186 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Passenger subscriptions
A summary of passenger app subscriptions is shown in Table 7-4.
Back-end publications
A summary of back-end application publications is shown in Table 7-5.
Pickmeup/drivers/driverId/inbox No 2
Pickmeup/passengers/passengerId/inbox No 2
Pickmeup/passengers/passengerId/location Yes 0
Pickmeup/passengers/passengerId Yes 0
Back-end subscriptions
A summary of back-end application subscriptions is shown in Table 7-6.
Pickmeup/payments False 2 No
We explain the core components of the iOS MQTT client and how they drive the application
through the stages described in 7.2, “Stages of the PickMeUp solution” on page 173. We also
describe the PickMeUp iOS passenger app. We cover two specific components of the
application:
Text and voice chat features
XCode storyboards for the user interface
Note: The iOS MQTT client is distributed as part of the IBM WebSphere MQ Client Pack,
which is available at this website:
https://www.ibm.com/developerworks/community/blogs/c565c720-fe84-4f63-873f-607d
87787327/entry/download?lang=en
One of the features of the iOS that the PickMeUp passenger app uses is the dispatch queues.
The application uses dispatch queues to guarantee serial processing of incoming MQTT
messages. When the MQTT client receives a message, the message is passed to the
onMessageArrived:message: method of the MqttCallbacks protocol. The application is then
able to move the message onto the dispatch queue that is running on the main thread of the
application, so that the client can continue receiving messages.
In the PickMeUp iOS passenger app, the PMUMessenger class stores the MqttClient object as
an instance variable.
In addition to the MqttClient class, there are three protocols and three structures that are
defined in the iOS MQTT client.
190 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
The PickMeUp iOS passenger app uses these methods to control the flow of the
application. The invocationContext argument will be set to one of the following
values:
• connect: Set when connecting to the MQTT broker
• disconnect: Set when disconnecting from the MQTT broker
• send: Set when publishing an MQTT message
• subscribe/topicFilter: Set when subscribing to the topic specified by topicFilter
• unsubscribe/topicFilter: Set when unsubscribing from the topic specified by
topicFilter
The appropriate action to take is determined based on the content of the
invocationContext argument passed into the callback.
MqttCallbacks protocol
The MqttCallbacks protocol specifies the callback methods that are used when an action
occurs that was not initiated by an MqttClient API call. For example,
onMessageArrived:message: is called when a message is published to the iOS MQTT
client.
There are three methods in the MqttCallbacks protocol:
– The onMessageArrived:message: method is invoked upon receipt of an MQTT
message.
– The onMessageDelivered:messageId: method is invoked upon successful delivery of
an MQTT message.
– The onConnectionLost:errorMessage: method is invoked if an unexpected disconnect
occurs between the client and the MQTT broker.
Similar to the InvocationComplete protocol, the first argument of each of these methods
provides the context for the callback.
The PickMeUp iOS passenger app uses these methods for handling events that are
received from the MQTT broker. When an MQTT message is passed to the
onMessageArrived:message: method, the application can parse the topic and data from
the message and handle it correctly.
MqttTraceHandler protocol
The MqttTraceHandler protocol specifies the methods that the iOS MQTT client uses to
print trace messages.
There are five severities for trace messages:
– Debug
– Log
– Info
– Warn
– Error
The PickMeUp iOS passenger app does not implement this protocol.
Both the MqttCallbacks and InvocationComplete protocol implementations for the PickMeUp
application are defined in PMUCallbacks.m.
Note: The iOS MQTT client is distributed as part of the IBM WebSphere MQ Client Pack,
which is available at this website:
https://www.ibm.com/developerworks/community/blogs/c565c720-fe84-4f63-873f-607d
87787327/entry/download?lang=en
192 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
PMUCallbacks: PMUCallbacks is not a class itself, but it contains the implementations of
both the MqttCallbacks protocol and the InvocationComplete protocol. For the
InvocationComplete protocol, a separate implementation exists for each API defined in the
MqttClient class.
PMUChatSender: PMUChatSender is an enumerated type that specifies whether the message
was sent by the passenger or the driver. There are two values:
– PMUChatPassenger for messages sent by the passenger
– PMUChatDriver for messages sent by the driver
This property is used by PMUMessageTableView to determine the positioning of the chat
message in the table.
In the passenger app, the chat subscription is created during the pairing stage, after a driver
has sent an accept status message to the passenger app.
Example 8-2 shows how a chat message is sent by the passenger app.
/* pickmeup/drivers/<driverId>/chat */
[messenger publish:[PMUTopicFactory getDriverChatTopic] payload:payloadString
qos:0 retained:NO];
In Example 8-2 on page 193, the application first constructs the JSON message content.
The message is then published by passing it to the PMUMessenger
publish:payload:qos:retained: method. After publishing the message to the driver’s
chat topic, a PMUMessage object is created with the JSON message content. The
PMUChatSender property of the PMUMessage is set to PMUChatPassenger to indicate that this
message was sent by the passenger. This is used later for determining the position of the
message in the chat table view. After creating the PMUMessage object, it is passed to the
PMUMessenger displayChatMessage:from: method.
194 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
options:NSJSONReadingMutableContainers
error:&error];
if (error)
{
NSLog(@"Error parsing json: %@", error);
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
// inbox pickmeup/passengers/<passenger_id>/inbox
if ([topicParts count] == 4 && [[topicParts objectAtIndex:3]
isEqualToString:PMUTopicInbox])
{
[self handleInboxMessage:json topic:topic];
}
// pickmeup/drivers/<driver_id>/location
else if ([topicParts count] == 4 && [[topicParts objectAtIndex:3]
isEqualToString:PMUTopicLocation])
{
[self handleLocationMessage:json topic:topic];
}
// pickmeup/drivers/<driver_id>/picture
else if ([topicParts count] == 4 && [[topicParts objectAtIndex:3]
isEqualToString:PMUTopicPicture])
{
[self handlePictureMessage:json];
}
// pickmeup/passengers/<passenger_id>/chat
else if ([topicParts count] == 4 && [[topicParts objectAtIndex:3]
isEqualToString:PMUTopicChat])
{
[self handleChatMessage:json topic:topic payload:payload];
}
// pickmeup/drivers/<driver_id>
else if ([topicParts count] == 3 && [[topicParts objectAtIndex:1]
isEqualToString:@"drivers"])
{
[self handleStatusMessage:json];
}
});
}
In Example 8-3 on page 194, the application checks the topic of the message to determine
the type of message that was received. For chat messages, it checks to determine whether
the end of the topic string is chat. If so, the message is passed to the
handleChatMessage:topic:payload: method. This method is shown in Example 8-4.
In Example 8-4 on page 195, the application parses the JSON string and uses the content to
create a PMUMessage object. All chat messages received from the driver have their
PMUChatSender property set to PMUChatDriver, which is used later for determining the
placement of the message in the chat table view. After creating the PMUMessage object, it is
passed to the PMUMessenger displayChatMessage:from: method.
[appDelegate.chatController reload];
if ([senderId isEqualToString:[PMUTopicFactory getPassengerId]] == NO)
{
// Only autoplay message if it came from the driver.
[appDelegate.chatController playMessageOnArrival:message];
}
}
In Example 8-5, the message is added to the messageCache array of the PMUAppDelegate
object. The chat table view is then reloaded to display the newly added chat message. If the
new message was sent by the driver and it is an audio message, the message is played
automatically upon receipt.
Finally, the chat message is drawn in the chat table. This is performed by the
UITableViewDelegate tableView:cellForRowAtIndexPath: method, as shown in
Example 8-6 on page 197.
196 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Example 8-6 Drawing a chat message in the table
/** Draw the table cell for a chat message.
*/
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([data.format isEqualToString:PMUAudioFormat])
{
UIButton *voiceButton = [self createAudioButtonSubview:bubbleImage];
[cell addSubview:voiceButton];
}
return cell;
}
Example 8-6 shows the method for drawing each table cell. Each cell corresponds to a
separate chat message. The messageCache array of PMUAppDelegate is used as the data
source for the chat table. For each PMUMessage object contained in messageCache, the
tableView:cellForRowAtIndexPath: method is called. The method gets a chat message from
messageCache using indexPath.row as the array index for accessing messageCache. Several
views are then created and added to the cell:
UIImageView avatarImage: Displays the picture of the sender of the message. For the
driver, this will appear to the left of the message content. For the passenger, this will
appear to the right of the message content.
UIImageView bubbleImage: The background image for the message content.
UIView textView: The view of the text within the chat bubble.
The frame for the avatar image is a fixed size. The frames for the other views are set
dynamically, based on the message content. The positioning of the chat message in the chat
table view depends on the value of the PMUChatSender property of the message. If the value of
the PMUChatSender property is PMUChatDriver, the message is positioned on the left side of
the chat table. If the value of the PMUChatSender property is PMUChatPassenger, the message is
positioned on the right side of the chat table. Figure 8-1 on page 198 displays the views of the
chat cells as they appear in the application.
2. textView
3. bubbleImage
1 All images on this page were taken using the iOS Simulator application from Apple Inc.
198 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Three storyboard files are used:
Main_iPhone.storyboard: Defines the user interface for a 4-inch Apple iPhone. A sample
from the storyboard is shown in Figure 8-2.
2 All images on this page were taken using the iOS Simulator application from Apple Inc.
3 All images on this page were taken using the iOS Simulator application from Apple Inc.
200 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Main_iPad.storyboard: Defines the user interface for an iPad. A sample from the
storyboard is shown in Figure 8-4.
Depending on the type of device on which the application is being run, it loads the appropriate
storyboard. This is done so that the application fits correctly on each of the various devices.
An alternative is to use constraints to define how the different elements of the storyboard
move and resize, based on the dimensions of the device.
4 All images on this page were taken using the iOS Simulator application from Apple Inc.
Note: The Java MQTT client and the Android Service are both distributed as part of the
open source Eclipse Paho project and are available at this website:
http://www.eclipse.org/paho/
One of the most important benefits of developing MQTT applications on Android is the
capability of the Android OS to execute long-running operations in the background, without
requiring any user input. By wrapping all of the messaging logic inside an Android Service
that continuously runs in the background, even when the application is not active, it is
possible to perform the following functions:
Ensure that the application messaging engine is always active and can receive and
process messages, regardless of the application, OS, or device state. This capability
includes waking up the CPU to send a keep alive message.
Offload message handling to a background thread by using a separate thread for the
Android Service.
Minimize the resource-intensive task of connecting to the MQTT broker by keeping a
long-running, open session.
Provide a clean separation of the application logic from the messaging engine.
The Eclipse Paho open source project (introduced in 1.2.4, “The Eclipse Paho project” on
page 9) provides an example implementation of the Android MQTT Service. The Eclipse
Paho Android Service is a simple-to-use interface to the Eclipse Paho Java MQTT client. It is
sufficient for an introduction to the MQTT messaging patterns in the Android application. If the
project requires a more low-level control of the messaging engine inside the application,
consider creating a project-specific version of Android Service that will take full advantage of
the Eclipse Paho Java MQTT client.
204 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
In this chapter, we focus on the following topics:
The Android implementation of the PickMeUp passenger app and how it uses the Eclipse
Paho Java MQTT client library. See 9.1, “Advantages of developing an Android PickMeUp
application” on page 204.
The implementation of the Eclipse Paho Android Service for asynchronous handling of
sending and receiving messages using the MQTT protocol. See 9.2.2, “Using the Eclipse
Paho Android service” on page 208.
The messaging part of the application and the interactions between the MQTT service and
the UI elements of the application. See 9.2.4, “Payment message flow” on page 209.
The flow of an incoming MQTT message through the Android application using an
example during the PickMeUp payment phase. See 9.2.4, “Payment message flow” on
page 209.
The Eclipse Paho Android Service is an open source interface to the Eclipse Paho Java
MQTT client library; however, it is important to mention that any Android Service can be
modified or implemented to handle MQTT messaging using the Eclipse Paho Java MQTT
client library.
Note: The Eclipse Paho Java MQTT client and Eclipse Paho Android Service are both
distributed as part of the open source Paho project and are available at this website:
http://www.eclipse.org/paho/
The Eclipse Paho open source project (introduced in 1.2.4, “The Eclipse Paho project” on
page 9) provides an example implementation of the Android MQTT Service. The Eclipse
Paho Android Service is a simple-to-use interface to the Eclipse Paho Java MQTT client, and
it is sufficient for an introduction to the MQTT messaging patterns in the Android application.
If the project requires a more low-level control of the messaging engine inside the application,
consider creating a project-specific version of Android service that will take full advantage of
the Eclipse Paho Java MQTT Client.
!
"
% &
The PickMeUp application on Android can be separated into four main blocks:
Android MQTT Service
The Android MQTT Service is an interface to the Eclipse Paho MQTT client library that
provides a long-running background service for handling the sending and receiving MQTT
messages.
PickMeUp Util Classes
The PickMeUp Util Classes are utility classes for a wide range of functions, including
facilitating the interaction between activities and the MQTT service and handling incoming
MQTT messages. The following classes are the most important:
– MqttHandler
MqttHandler is a utility class that holds an instance of the MqttAndroidClient class and
interacts with the MQTT service. This helper class performs all of the basic operations
on the MqttAndroidClass, such as connect, disconnect, subscribe, unsubscribe, and
publish.
MqttHandler implements MqttCallback, which allows it to process incoming messages
from the MQTT service. MqttHandler does not hold any application logic that
processes the incoming messages. That logic is offloaded to the MessageConductor
utility class.
206 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
– ActionListener
ActionListener is a utility class that is instantiated every time an Android MQTT client
API is used. ActionListener implements the IMqttActionListener class to notify the
application if the API call was successful.
The Android PickMeUp passenger app uses ActionListener methods to control the
flow of the application. When onSuccess(...) is called for a successful connection, the
application then creates the subscription to the passenger inbox topic. When
onSuccess(...) is called for successfully subscribing to the inbox topic, the application
begins publishing its presence, request, photo, and location messages.
– MessageFactory
MessageFactory is a simple helper class that constructs messages in the format
expected by the PickMeUp driver application (referred to as the driver app in this
chapter). The messaging patterns implemented in the PickMeUp application require that
all messages are formatted as JavaScript Object Notation (JSON). MessageFactory
always returns a JSON-formatted string that can be used directly as a message
attribute inside the publish(...) method.
– TopicFactory
TopicFactory is a convenience class that constructs required messaging topics from
the application constants and the driver and passenger variables.
– MessageConductor
MessageConductor holds all of the application logic for routing the incoming MQTT
message to the correct area of the application. By inspecting the incoming MQTT
message topic and payload, MessageConductor creates an intent with the message
payload data and broadcasts it to a RouterReceiver or a specific broadcast receiver
that is registered directly with an activity.
For convenience, all of the utility classes are grouped in the com.ibm.PickMeUp.utils
package.
Broadcasts
Broadcasts is a group of BroadcastReceivers that facilitates communications between
activities and other parts of the application:
– RouterReceiver
RouterReceiver is a BroadcastReceiver that is registered directly with the PickMeUp
application at the manifest level. The role of the RouterReceiver is to catch broadcasts
from the MessageConductor, and then process them by performing one of the following
actions:
• Starting a new activity
• Pushing the incoming message to another utility class for processing
• Rethrowing the broadcast if it needs to be handled directly by an activity
PickMeUp activities
PickMeUp activities is a group of application components that provides graphical interface
and capabilities for user interaction. Each PickMeUp activity extends Android activity and
uses the layout defined within the XML layout files that are inside the application
resources. Several of the activities register BroadcastReceivers to interact with other
parts of the application through broadcasted messages.
For convenience, all the activities are grouped under the com.ibm.PickMeUp.activities
package.
208 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
The MqttCallback interface
The MqttCallback interface specifies the callback methods that are used when an action
occurs that was not initiated by an MqttAndroidClient API call. For example,
messageArrived(String topic, MqttMessage message) is called when a message is
published to the Android MQTT client.
There are three methods in the MqttCallback interface:
– The messageArrived(String topic, MqttMessage message) method is invoked upon
the receipt of an MQTT message.
– The deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) method is invoked
upon the successful delivery of an MQTT message.
– The connectionLost(Throwable throwable) method is invoked if an unexpected
disconnect occurs between the client and the MQTT broker.
The Android PickMeUp passenger app uses these methods for handling events that are
received from the MQTT broker. When an MQTT message is passed to the
messageArrived(...) method, depending on the topic and the message payload, the
application is then able to handle the message correctly.
For the Android PickMeUp passenger app, the MqttCallback interface is implemented by
the MqttHandler class.
Example 9-1 shows the passenger inbox topic used in this scenario.
Pickmeup/passengers/<passengerId>/inbox
Example 9-2 shows the payload of the message that is sent to the passenger inbox topic after
the trip ends.
{"type":"tripEnd","distance":"14.20","time":13,"cost":"15.76"}
Example 9-3 on page 210 shows the message as received by the Android MQTT Service that
is sent to the messageArrived(String topic, MqttMessage mqttMessage) method inside the
PickMeUp MqttHandler.
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws
Exception {
Log.d(TAG, ".messageArrived() entered");
String payload = new String(mqttMessage.getPayload());
Log.d(TAG, ".messageArrived - Message received on topic " + topic
+ ": message is " + payload);
try {
// send the message through the application logic
MessageConductor.getInstance(context).steerMessage(payload, topic);
} catch (JSONException e) {
Log.e(TAG, ".messageArrived() - Exception caught while steering a
message", e.getCause());
e.printStackTrace();
}
}
Example 9-4 steerMessage(...) method to apply the application logic to the incoming MQTT message
After a JSONObject is created from the MQTT message payload, it runs through the
application logic to determine which message the application is dealing with. Then, the
JSONObject sends a broadcast message, depending on the situation. For a tripEnd
message, the code shown in Example 9-5 is executed.
..................................................................................
..................................................................................
} else if
(topic.equals(TopicFactory.getInstance(context).getPassengerInboxTopic()) &&
jsonPayload.has(Constants.TYPE)) {
if (jsonPayload.get(Constants.TYPE).equals(Constants.TRIP_START)) {
210 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
// trip ended message - collect time, distance, cost and send to
the router
Intent actionIntent = new
Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE,
Constants.ACTION_INTENT_END_TRIP);
String time = jsonPayload.getString(Constants.TIME);
String distance = jsonPayload.getString(Constants.DISTANCE);
String cost = jsonPayload.getString(Constants.COST);
actionIntent.putExtra(Constants.TIME, time);
actionIntent.putExtra(Constants.DISTANCE, distance);
actionIntent.putExtra(Constants.COST, cost);
context.sendBroadcast(actionIntent);
} else if
(jsonPayload.get(Constants.TYPE).equals(Constants.TRIP_PROCESSED)) {
}
}
In Example 9-5 on page 210, we see that the steerMessage(...) method inspects the topic
and the payload to match them to a passenger inbox topic and the tripEnd message type. In
addition, there is a check that the payload has the time, cost, and distance values to avoid an
exception when attempting to obtain those values from the payload.
A new intent is created with the action attribute set to the same value as the intent filter for
the RouterReceiver broadcast receiver. To eliminate the need for the RouterReceiver to go
through the complex logic of determining the origin and the destination of the incoming
message, an internal flag ROUTE_MESSAGE_TYPE is used. In addition, all of the important parts
of the message payload are added to the intent before the intent is broadcasted.
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, ".onReceive() entered");
if
(intent.getStringExtra(Constants.ROUTE_MESSAGE_TYPE).equals(Constants.ACTION_INTEN
T_DRIVER_DETAILS_RECEIVED)) {
// driver details received
driverDetailsReceived(context, intent);
} else if
(intent.getStringExtra(Constants.ROUTE_MESSAGE_TYPE).equals(Constants.ACTION_INTEN
T_START_TRIP)) {
The RouterReceiver is designed to take action on most of the messages that come through
the MQTT service. The logical split between the RouterReceiver and the MessageConductor is
for the MessageConductor to understand what the incoming message relates to and which
data needs to be extracted from it, and for the RouterReceiver to take action using the
incoming message data.
After the RouterReceiver receives the endTrip message, a new activity is started, which is
named the TripEndDetailsActivity. This activity displays the details about the trip, such as
the cost, distance traveled, and the time. It also provides a method for the passenger to rate
the driver and add a tip for services, as demonstrated in Figure 9-2 on page 213.
212 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 9-2 Trip Details window that follows the received tripEnd message
After the passenger clicks the Submit Payment button (Figure 9-2), the next messaging cycle
is initiated. The trip cost, driver rating, and tip are added to the intent that is used to start the
PaymentSentActivity. As shown in Example 9-8, the PaymentSentActiviy is preparing to
submit the payment message and publish it to the payment topic.
// get trip cost, total payment, rating and the tip passed inside the
startActivity intent
String cost = getIntent().getStringExtra(Constants.COST);
String tip = getIntent().getStringExtra(Constants.TIP);
String rating = getIntent().getStringExtra(Constants.RATING);
..................................................................................
..................................................................................
// get hold of the utils
MqttHandler mqttHandler = MqttHandler.getInstance(this);
TopicFactory topicFactory = TopicFactory.getInstance(this);
MessageFactory messageFactory = MessageFactory.getInstance(this);
TopicFactory
TopicFactory getPassengerPaymentTopic() returns a topic string to be used when publishing
the message (Example 9-9).
Pickmeup/payments
MessageFactory
MessageFactory getPaymentMessage(String cost, String tip, String rating) is used to
generate a JSON formatted string for the message payload, as shown in Example 9-11.
Example 9-11 Generating JSON formatted payload for the payment message
In Example 9-11, a JSONObject is created, and all of the relevant message details are added
to the object before returning its string representation. The universally unique identifiers
(UUIDs), one for the driver app and one for the passenger app, are added to the message
payload, as shown in Example 9-12. The Driver ID is taken from the PickMeUpApplication
class where the UUID is stored in memory as a globally shared variable. The Passenger ID is
taken from the Android SharedPreferences, where it is stored during the login stage.
Example 9-12 String representation of the JSON object returned from the getPaymentMessage(...)
{"rating":"0","cost":"17.6","passengerId":"Bob","tip":"0","driverId":"Jessie"}
214 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
MqttHandler
MqttHandler publish(String topic, String message, boolean retained, int qos) is used
to publish the message to the topic, as shown in Example 9-13.
To publish the message, a new MqttMessage is created from the message string and retained
flag. The quality of service (QoS) is set on the message, too. An instance of ActionListener
is created to track whether the publish API call was successful. The publish method is then
called on an instance of MqttAndroidClient.
The JavaScript MQTT client connects to an MQTT broker over the HTML5 websockets
transport. Therefore, a browser supporting the HTML5 websockets specification must be
used. The following minimum browser versions are required to run the MQTT client for several
common browsers:
Internet Explorer 10+
Firefox 21+
Chrome 21+
Safari 6+
Opera 12.1+
iOS (Safari) 6+
Android OS 4.4+
218 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Example 10-1 How TopicManager obtains a passenger location topic
var TopicManager = (function() {
var _basePassengerTopic = “pickmeup/passengers/”;
var _passengerId = null; // will be set
...
var getPassengerLocationTopic = function() {
return _basePassengerTopic + _passengerId + "/location";
}
…
return {
getPassengerLocationTopic: getPassengerLocationTopic,
…
};
})();
220 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
The Messenger namespace contains functions to connect, disconnect, publish, and
subscribe. These functions are called by the driver application and use the four management
objects (TopicManager, MessageFactory, SubscriptionFactory, and MessageHandler) to build
the appropriate MQTT messages and subscription data. Example 10-5 shows the Messenger
namespace publish and subscribe functions, which use objects created by the
MessageFactory and SubscriptionFactory to call the JavaScript MQTT client publish and
subscribe methods.
…
var _client = new Messaging.Client(SERVER, PORT, CLIENT_ID);
_client.subscribe(topic, {
qos: qos,
onSuccess: onSuccess
});
}
…
return {
…
publish: publish,
subscribe: subscribe,
…
}
})(window);
222 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
11
11.1.1 Prerequisites
The following prerequisites must be met to run the PickMeUp iOS passenger app:
You must be using a Macintosh computer to run the PickMeUp iOS passenger app. If you
are not using a Macintosh computer, you can still view the source code for the project, if
you want.
Xcode must be installed to open the PickMeUp.xcodeproj file.
You are required to have an iOS developer certificate to deploy the application to a
physical device. Otherwise, the application can only be run on the iOS simulator. With an
iOS developer certificate, the application can be installed onto an iOS device, such as an
iPad or iPhone.
Optionally, you must have Git source code management (SCM) installed to the source
using the git clone command. For details, see 11.1.2, “Obtain the PickMeUp iOS source
code” on page 224.
Obtain the source code from the Redbooks repository using FTP
To obtain the source code from the Redbooks repository using FTP, follow these steps:
1. Download the PickMeUp-iOS.zip file from the Redbooks FTP site to your computer. For
the download instructions, see Appendix B, “Additional material” on page 245.
2. Open a Finder window and navigate to the directory that contains the downloaded file.
Figure 11-1 on page 225 shows the PickMeUp-iOS.zip file in the PickMeUpWorkspace.
224 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 11-1 Finder window showing the downloaded PickMeUp-iOS.zip file1
1 All images on this page were captured using Xcode, which is a trademark of Apple Inc., registered in the U.S. and other countries.
Chapter 11. Download, deploy, and run PickMeUp in iOS, Android, and HTML environments 225
Figure 11-3 Contents of the project directory2
2. Open the PickMeUp.xcodeproj file. Figure 11-4 shows the Xcode project after it is
opened.
2 All images on this page were captured using Xcode, which is a trademark of Apple Inc., registered in the U.S. and other countries.
226 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
11.1.4 Configure the project build settings
After opening the project, check the build settings to ensure that they are configured correctly
to successfully build and run the application. The following properties need to be set up:
1. Set the Build For Active Architecture only property. To change this setting, click the current
value for a list of available options.
Figure 11-5 shows the property after it is set to the correct value, No.
Figure 11-5 Set the Build Active Architecture Only property to No3
2. Set the Install Owner property. To change this setting, click the current value and edit it.
Figure 11-6 shows the property after it is set to the correct value, $(USER).
3
All images on this page were captured using Xcode, which is a trademark of Apple Inc., registered in the U.S. and
other countries.
Chapter 11. Download, deploy, and run PickMeUp in iOS, Android, and HTML environments 227
3. Set the Library Search Paths property. To add or change any of the paths listed, click the
current value and enter your change. We suggest setting the following paths to
non-recursive:
– $(inherited)
– $(PROJECT_DIR)
– $(PROJECT_DIR)/PickMeUp
– $(PROJECT_DIR)_/PickMeUp/Lib
Figure 11-7 shows the Library Search Paths after they are set to the correct values.4
4. Set up the Code Signing identity and provisioning profile. To view or change this profile,
select your developer certificate and provisioning profile, and then set the properties to the
following suggested values:
Code signing identity: <Multiple values>
Debug: Don’t Code Sign
Any iOS SDK iOS Developer
Release: Don’t Code Sign
Any iOS SDK iOS Developer
...
Provisioning Profile None
Note: The code signing identity and provisioning profile require a valid developer
certificate.
Figure 11-8 on page 229 shows the Code Signing properties to set.
4
All images on this page were captured using Xcode, which is a trademark of Apple Inc., registered in the U.S. and
other countries.
228 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Figure 11-8 Set the Code Signing identity and provisioning profile as shown5
5
All images on this page were captured using Xcode, which is a trademark of Apple Inc., registered in the U.S. and
other countries.
Chapter 11. Download, deploy, and run PickMeUp in iOS, Android, and HTML environments 229
2. Launch the application.
To launch the application, click the play (triangle) icon in the upper-left corner of the
window (red rectangle in Figure 11-9 on page 229).
3. Optional: Stop the application.
To stop the application, click the Stop (square) icon in the upper-left corner of the window
(red rectangle in Figure 11-9 on page 229).
11.2.1 Prerequisites
The following prerequisites must be met to run the PickMeUp Android application:
An Android device with Android 4.1 Jelly Bean (API level 16) or higher is required to run
the application.
Notes:
Running PickMeUp on an emulator is not advised, because PickMeUp is using Google
Play Services and Location Services. Using an emulator might cause the application
to run with reduced functionality.
The application was tested using Google Nexus 4, Google Nexus 7, and the
Samsung Galaxy S4. For best viewing, we suggest using the screen sizes provided
with these devices as the minimum screen sizes.
A Google account and Google Maps Android API v2 key are required to build the
application.
Android Software Development Kit (SDK) is required to build the PickMeUp application.
Stand-alone SDK tools and Eclipse or Android Studio bundle can also be used.
The PickMeUp source code includes a Gradle build file. This file can be run using Gradle
command-line tools, Android Studio integrated development environment (IDE), or Eclipse
(with the Gradle plug-in).
230 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
11.2.2 Register with Google Maps API
Open a Google account and register for Google Maps API. Any Google account can be used
to obtain the key for debugging and development purposes.
Note: Before building the PickMeUp application, a Google Maps API key is required. To
obtain a Google Maps API key, follow this link. After signing in, press Create:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backen
d&keyType=CLIENT_SIDE_ANDROID&r=9F:22:30:50:6D:43:4D:E7:FB:98:79:76:DC:67:E1:1B
:CF:9A:01:10%3Bcom.ibm.Pickmeup
After the key is generated, replace the google_maps_key entry with the key inside the
following file:
<workspace>/PickMeUp/app/src/debug/res/values/google_maps_api.xml
11.3.1 Prerequisites
The PickMeUp back end is a Node.js application, so you have to have Node.js installed in your
environment. If you want to install it on your local environment, access the Node.js website for
more details about setting it up:
http://nodejs.org/
For deployment simplification, you can use the IBM Bluemix environment, which is a Platform
as a Service (PaaS) solution from IBM. For more information, see this website:
http://www-01.ibm.com/software/ebusiness/jstart/bluemix/
Chapter 11. Download, deploy, and run PickMeUp in iOS, Android, and HTML environments 231
Use the CloudFoundry command-line interface (CLI) to interact with Bluemix. The
CloudFoundry CLI can be downloaded using this link:
https://github.com/cloudfoundry/cli/releases/tag/v6.1.0
Note: The PickMeUp back end is lightweight, so the Bluemix trial no-charge option is
usually sufficient for trying PickMeUp.
Example 11-1 MessageSight server configuration for the PickMeUp back end
mqtt: {
host: '<your.server.ip.goes.here>',
port: <your.server.port.goes.here>
}
3. Target the Bluemix environment for which you registered. See Example 11-2.
6. Navigate to the directory to which you extracted the PickMeUp back-end code.
7. Deploy the code using the $cf push Pickmeup --no-route command shown in
Example 11-5.
232 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
8. Optional: After the application is deployed, you can view the log file when you are running
PickMeUp. Use the $cf logs Pickmeup command shown in Example 11-6.
Chapter 11. Download, deploy, and run PickMeUp in iOS, Android, and HTML environments 233
234 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
A
Note: The IBM developerWorks® website contains the MQ Telemetry Transport (MQTT)
V3.1 Protocol Specification at this website:
http://www.ibm.com/developerworks/webservices/library/ws-mqtt/index.html
A real-life comparison can be made with letters that are mailed using the postal service. An
informal letter to a friend can be dropped into a mailbox, and the sender might never think
about it again. The sender expects the letter to arrive at its destination, but there are no
significant consequences if it does not arrive. In contrast, a letter to which the recipient must
respond is more important, so the sender might choose a higher level of delivery service that
provides proof that the letter was received at its destination. In each situation, the choices
made by the sender of the letter are comparable to choosing QoS levels in MQTT.
The MQTT command message used is PUBLISH. No other command messages flow for
QoS 0 messages. Table A-1 shows the QoS 0 protocol flow.
236 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
If the client does not receive a PUBACK message (either within a time period defined in the
application, or if a failure is detected and the communications session is restarted), the client
resends the PUBLISH message with the DUP flag set. When it receives a duplicate message
from the client, the MQTT server republishes the message to the subscribers, and sends
another PUBACK message. On the client side, the implementation of the MQTT protocol also
provides an additional feature known as MQTT persistence. The MQTT persistence layer is
not described in the MQTT specification, but it is normally available with MQTT client
implementations. When a QoS 1 message is published to the server, the client needs to wait
for the acknowledgment to arrive. There can be a program termination or a crash at the client
device. When the client is started again, it will need to resume from the point it left before the
crash. Therefore, the message is stored in a persistence layer, such as disk, and retrieved
soon after the reconnecting back to the MQTT server.
The MQTT command messages used are PUBLISH and PUBACK. When the publish
happens, the message will be logged to the MQTT persistence and removed when PUBACK
is received. A message with QoS 1 has a Message ID in the message header. Table A-2
shows the QoS 1 protocol flow.
The MQTT command messages used are PUBLISH, PUBREC, PUBREL, and PUBCOMP.
The message is sent in the PUBLISH flow, and the client stores that message in the MQTT
persistence layer, if used. The message remains locked on the server. PUBREC is sent by the
server in response to PUBLISH. PUBREL is dispatched to the server from the client in
response to PUBREC. After PUBREL is received by the MQTT server, the messages can be
dispatched to the subscribers and PUBCOMP is sent back in response to the PUBREL. A
QoS 2 message has a Message ID in the message header.
If a failure is detected, or after a defined time period, each part of the protocol flow is retried
with the DUP bit set. The additional protocol flows ensure that the message is delivered to
subscribers one time only.
Because QoS 1 and QoS 2 indicate that messages must be delivered, the MQTT server
stores messages in a database. If the MQTT server has problems accessing this data,
messages might be lost. Table A-3 on page 238 shows the QoS 2 protocol flow.
PUBREC Message ID = x
<-----------
From the MQTT perspective, it is assumed that the client and server are generally reliable,
and that the communications channel is more likely to be unreliable. If the client device fails, it
is typically a catastrophic failure, rather than a transient one. The possibility of recovering data
from the device is low. Certain devices have nonvolatile storage, for example, flash ROM. The
provision of more persistent storage on the client device protects the most critical data from
certain modes of failure.
Beyond the basic failure of the communications link, the failure mode matrix becomes
complex, resulting in more possible scenarios than the specification for MQTT can handle.
The time delay (the retry interval) before resending a message that has not been
acknowledged is specific to the application, and it is not defined by the protocol specification.
QoS determination
When the client subscribes to a topic, the QoS level is selected. Consider a scenario where
Publisher A is sending messages to a topic at QoS 2. A subscriber can subscribe at QoS 0,
so that the messages to the client are delivered with QoS 0. The QoS value is further used in
SUBSCRIBE and UNSUBSCRIBE requests. A subscribe request from the client is a QoS 1
request, to which the server responds with SUBACK, which ensures that the subscription has
occurred.
238 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Impact of QoS level on performance
There is a simple rule when considering the performance impact of QoS: The higher the QoS,
the lower the performance. Let us evaluate performance corresponding with higher QoS.
Suppose the time taken for sending a PUBLISH message is pt. If QoS 0 is used, the total time
taken to transfer n number of messages is npt. Now, for QoS 1, the PUBACK message (that
is, the reply to the PUBLISH message) flows from the server to the client. This is a 2-byte
message and typically takes less time than pt takes. Therefore, the time for the reply to the
PUBLISH message is called mt. So, the time taken for transferring n messages is n(pt + mt).
For example, for QoS 2, the PUBREC, PUBREL, and PUBCOMP messages are flowing.
Therefore, n number of messages takes approximately n(pt + 3mt). So, if 10 messages need
to be transferred from client to server, and pt is 1 second and mt is 0.4 seconds, a QoS 0
message takes 10x1 (or 10 seconds). By comparison, QoS 1 messages take 10(1+0.4) (or 14
seconds), and QoS 2 messages take 10(1+1.2) (or 22 seconds).
MQTT restricts the client ID length to 23 characters. Certain situations require that the client
ID is shortened. As an example, if the MAC address of the client’s machine is used as the
MQTT client ID, the client needs to shorten the ID to meet the 23-character limit. When
shortening the client ID, the client ID cannot be the same as any other client ID on the
network. To keep the client ID short and unique, we suggest that the client introduce a reliable
ID generation mechanism. For instance, you might create a client identifier from the 48-bit
device MAC address. If transmission size is not a critical issue, you might use the remaining
17 bytes to make the address easier to administer, such as human-readable text in the
identifier.
If two clients were to have the same client identifier, one of the clients might receive a
message and the other client might not. The MQTT server tracks the pending messages that
are to be sent to a client based on the client ID. Therefore, if a client has been using QoS 1 or
QoS 2, and has subscribed to any topic and disconnected from the server, the server saves
the messages that arrived for the client when it was disconnected. After the client reconnects,
the server sends those messages to the client. If a second MQTT device uses the same client
ID and connects to the server, the server will send the saved messages to the second device.
Another scenario related to the client IDs is duplicate connections. Assume that a particular
device using client ID DeviceA is connected to the MQTT server. If another client logs in with
the same client ID DeviceA, the first (older) client must be disconnected by the server before
completing the CONNECT flow of the second (new) client. This is an optional feature of an
MQTT server.
A non-durable subscriber is any client that does not intend to receive messages published
when it is inactive. A client is said to be non-durable in the following cases:
A client always uses the clean session flag set to true when it connects to the server.
A client always unsubscribes for all the topics it is subscribed to, before disconnecting.
In MQTT, QoS 0 messages are never persisted when a durable subscriber is inactive. Only
QoS 1 and QoS 2 messages are persisted by the server and sent when the client becomes
active. MQTT further provides a facility that allows MQTT clients to refrain from receiving
messages when they were disconnected by setting the clean start flag to true. The following
example flow is for a typical durable MQTT subscriber:
1. MQTT ClientA connects to the server by specifying the clean session flag as false.
2. ClientA subscribes to the topic with QoS 2.
3. MQTT ClientB connects to the server and publishes QoS 1 and QoS 2 messages to the
topic.
4. ClientA receives the messages.
5. ClientA disconnects from the server. Note that ClientA did not unsubscribe.
6. ClientB publishes more QoS 1 and QoS 2 messages.
7. ClientA connects to the server by specifying the clean session flag as false.
8. ClientA receives all of the messages that were published when it was inactive and all
future messages that are published to the topic.
Durable subscribers are useful when the subscribing MQTT client needs all of the messages
that are published to the topic it subscribes to. For durable subscribers, an MQTT client is
assured to receive any messages when it was disconnected or even had lost a connection.
Although durable subscriptions is a nice feature, it adds the additional requirement of the
server to hold messages until the client reconnects to the server.
MQTT persistence
The MQTT protocol is designed with the assumption that the client and server are generally
reliable. This means that the client machine and the server machine will not crash, hang, or
have power failure issues. The assumption might prove to be costlier in certain situations for
the clients and, therefore, a feature known as MQTT client persistence is provided. The local
persistence store is used to achieve QoS 1 and QoS 2 level message flows. For example,
before the client sends the PUBLISH command, the client stores the message data on disk or
any other available storage.
240 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
The client, when it receives an acknowledgment, deletes the message from the disk. In the
case of a power failure followed by a restart of the client application, one of the first actions
after the reconnect is to check for pending client messages and to send them. On the server
side, this feature is generally managed by the messaging engine itself.
For the best reliability but slowest messaging rates, send persistent JMS messages and user
per-message acknowledgment. This configuration provides up to QoS 2 for MQTT
subscribers. Table A-4 shows the possible combinations for message delivery from JMS to
MQTT.
As you can see from this example, the overhead for every message is fixed at 2 bytes. The
total overhead is 140 - 80 = 60 bytes for this scenario.
For MQTT, the client only needs to tell the server that it is alive when no interaction has
occurred between them for a certain period of time. The time period is a configurable option.
This option can be set when connecting to the server by the client. It is the client that chooses
the keep alive time; the server just keeps a record of the value in the client information table
on the server side.
There are two messages that constitute the keep alive interaction:
PINGREQ: The ping request is sent by the client to the server when the keep alive timer
expires.
PINGRESP: The ping response is the reply sent by the server to a ping request from the
client.
Both of these messages are short, 2-byte messages. They are not associated with any QoS.
The PINGREQ is sent only one time, and the client waits for the PINGRESP.
Internally, there is a simple timer that triggers in the client. The timer determines whether
there has been recent activity between the client and the server. If not, a PINGREQ is sent.
The client waits until a PINGRESP is received. On the server side, if there is no message
received from the client within the keep alive time period, the server disconnects the client.
However, the server offers a grace period to the client, which is an additional 50% of the keep
alive time period.
When choosing a keep alive time for a client, there are certain considerations. If the MQTT
client is less active, sending, for example, one or two messages within an hour, and if the
keep alive timer is set to a low value, for example, 10 seconds, the network might be flooded
with PINGREQ and PINGRESP messages.
242 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Alternatively, if the keep alive timer is set to a high value, for example, one hour and the client
goes out of the network, the server will not know that the client has gone away for a long time.
This can affect administrators who monitor the connected clients. Also, the server will keep
retrying PUBLISH messages. Set the keep alive timer to suit your specific needs, based on
the message flow and the amount of time that the client can be idle.
It is possible that a duplicate message is received by an MQTT client when using QoS 1, due
to retries by MQTT. On slow and fragile networks, you can observe a large number of
duplicate messages that have occurred because of retry processing. If the retry timeout
period is short, the network can be clogged with a large number of duplicates.
If an unexpected disconnect occurs when the client does not send a DISCONNECT command to
the server, the publication is sent by the telemetry service when it detects that the connection
to the client has broken, without the client requesting a disconnect. The client might have
experienced a loss in network connection or an abrupt termination of the client program. The
publication is sent to a server for publishing messages to another application that is
monitoring the status of connected clients.
When a client connects to the server, the following last will and testament parameters can be
specified:
The topic to which the Will message needs to be published
The message that needs to be published
The QoS of the message that will be published on the topic
The retain flag that signifies whether the message will be retained
When the client unexpectedly disconnects, the keep alive timer on the server side detects that
the client has not sent any message or a keep alive PINGREQ. When this situation occurs,
the server publishes the last will and testament message on the topic specified by the client.
The publisher of the message sets this flag on the message during publishing. The following
example flow shows you how to understand retained messages:
1. Client A connects to the server and subscribes to topics a/b.
2. Client B connects to the server and publishes the message “Hello” with the retain flag to
topics a/b.
3. Client A receives the message without the retain flag set to 0.
4. Client C connects to the server and subscribes to topics a/b.
5. Client C receives the message with the retain flag set to 1.
Even if the server is restarted, the retained message will not be lost.
The retained publications are primarily used to maintain state information. If a particular topic
is used to publish a state message from a device, the messages can be retained messages.
The advantage is that the new monitoring program that connects can subscribe to this topic
and get information about the last published state messages from the device.
TCP/IP port 1883 is reserved for use with MQTT. TCP/IP port 8883 is also registered for
using MQTT over Secure Sockets Layer (SSL).
244 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
B
Select Additional materials and open the directory that corresponds with the IBM Redbooks
form number, SG248228.
http://www.eclipse.org/paho/clients/java/
246 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
Related publications
The publications listed in this section are considered particularly suitable for a more detailed
discussion of the topics covered in this book.
IBM Redbooks
The following IBM Redbooks publications provide additional information about the topic in this
document. Note that some publications referenced in this list might be available in softcopy
only.
Building Smarter Planet Solutions with MQTT and IBM WebSphere MQ Telemetry,
SG24-8054
The Interconnecting of Everything, an IBM Redbooks Point-of-View publication:
https://www14.software.ibm.com/webapp/iwm/web/signup.do?source=sw-app&S_PKG=ov2
1861&S_TACT=109KA8NW
You can search for, view, download or order these documents and other Redbooks,
Redpapers, Web Docs, draft and additional materials, at the following website:
ibm.com/redbooks
Online resources
These websites are also relevant as further information sources:
A demo collection that showcases dynamic HTML5 applications using IBM MessageSight
and MQTT for real-time analytics, communication, and collaboration:
http://m2m.demos.ibm.com
Restoring the MessageSight configuration data to the same appliance:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Back
up/ba00002_.html?lang=en
Restoring the MessageSight configuration data to a different appliance:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Back
up/ba00003_.html?lang=en
Message hub commands in the MessageSight IBM Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Refe
rence/MsgHubCmd/messagehubcommands.html?lang=en
A trial version of the key fob remote application is available at the following URL:
http://bit.ly/keyfobremote
Message hub commands in the MessageSight IBM Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Refe
rence/MsgHubCmd/messagehubcommands.html?lang=en
248 Building Real-time Mobile Solutions with MQTT and IBM MessageSight
MessageSight V1.1 Command Reference guide in the MessageSight IBM Knowledge
Center website:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Refe
rence/intro.html
Message hub commands in the MessageSight IBM Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Refe
rence/MsgHubCmd/messagehubcommands.html?lang=en
FIPS:
http://www.itl.nist.gov/fipspubs/
Configuring an external LDAP server in the IBM MessageSight Knowledge Center:
http://www-01.ibm.com/support/knowledgecenter/SSCGGQ_1.1.0/com.ibm.ism.doc/Admi
nistering/ad00371_.html?lang=en
MQTT V3.1 Java and C clients, which IBM contributed, and which you can download from
the following web pages:
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.c.git/
Node.js website:
http://nodejs.org/
IBM Bluemix environment (Platform as a Service (PaaS) solution from IBM). For more
information, see this website:
http://www-01.ibm.com/software/ebusiness/jstart/bluemix/
Bluemix trial at no-charge at this website:
https://ace.ng.Bluemix.net/
CloudFoundry CLI:
https://github.com/cloudfoundry/cli/releases/tag/v6.1.0
All the scoreboards are sponsored and developed by IBM using IBM MessageSight at
both the US Open and Wimbledon:
– US Open:
http://www.usopen.org/en_US/scores/index.html?promo=subnav
– Wimbledon:
http://www.wimbledon.com/en_GB/scores/
– The Australian open live score application can be accessed from the following URL:
http://www.ausopen.com/en_AU/scores/
Provides practical MQTT is a messaging protocol designed for the Internet of Things (IoT).
It is lightweight enough to be supported by the smallest devices, yet INTERNATIONAL
guidance to getting
robust enough to ensure that important messages get to their TECHNICAL
started quickly with
destinations every time. With MQTT devices, such as energy meters, SUPPORT
MQTT and IBM cars, trains, mobile phones and tablets, and personal health care ORGANIZATION
MessageSight devices, devices can communicate with each other and with other
systems or applications.
Builds a mobile IBM MessageSight is a messaging appliance designed to handle the
application scale and security of a robust IoT solution. MessageSight allows you to
(PickMeUp) by using easily secure connections, configure policies for messaging, and scale BUILDING TECHNICAL
MQTT and IBM to up to a million concurrently connected devices. INFORMATION BASED ON
PRACTICAL EXPERIENCE
MessageSight This IBM Redbooks publication introduces MQTT and MessageSight
through a simple key fob remote MQTT application. It then dives into IBM Redbooks are developed
Shows typical usage the architecture and development of a robust, cross-platform Ride by the IBM International
patterns and Share and Taxi solution (PickMeUp) with real-time voice, GPS location Technical Support
sharing, and chat among a variety of mobile platforms. The publication Organization. Experts from
guidance to expand also includes an addendum describing use cases in a variety of other IBM, Customers and Partners
the solution domains, with sample messaging topology and suggestions for design. from around the world create
timely technical information
based on realistic scenarios.
Specific recommendations
are provided to help you
implement IT solutions more
effectively in your
environment.