Mobile and Web Messaging
by Jeff Mesnil
Copyright 2014 Jeff Mesnil. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editors: Simon St. Laurent and Allyson MacDonald
- Production Editor: Nicole Shelby
- Copyeditor: Jasmine Kwityn
- Proofreader: Gillian McGarvey
- Indexer: Ellen Troutman
- Interior Designer: David Futato
- Cover Designer: Randy Comer
- Illustrator: Rebecca Demarest
- August 2014: First Edition
Revision History for the First Edition
- 2014-08-08: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491944806 for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the OReilly logo are registered trademarks of OReilly Media, Inc. Mobile and Web Messaging, the image of a song thrush, and related trade dress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and OReilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
978-1-491-94480-6
[LSI]
A Marion, la lumire qui claire mes pas.
Preface
The use of small smart devices is increasing and widening. Smartphones and tablets are connected to the Internetand automation devices, home devices, car systems, and more are joining them. Even though these devices are increasingly powerful, they have some constraints compared to desktop devices, including limited battery life and memory, as well as intermittent network availability. They require efficient protocols to communicate with other devices and servers while preserving their battery and memory usage.
Messaging technology enables us to overcome some of these constraints by providing protocols that efficiently use the most critical resources (network bandwidth and memory usage) and guarantee that the data will be effectively delivered even in the event of loss of network connectivity.
Applications are increasingly running inside web browsers or using web technology. Messaging concepts apply for these applications too, and can make them more efficient and responsive.
Messaging concepts are well-known in the enterprise software domain, but they are only starting to spread out to other software domains, including mobile and web computing. Developers writing software for these domains need good documentation to leverage these messaging technologies, using them when they make sense while avoiding their pitfalls.
This book provides an introduction to the messaging protocols to help software developers use them in mobile and web applications.
What This Book is About
This is a book about messaging protocols and how software developers can use them to build more responsive, resilient applications running on mobile devices and web browsers.
Messaging protocols are nothing new. They have been used with success in enterprise software for many years, and have been one of the building blocks that let different services and platforms communicate with one another. Their designs make them well-suited to building applications for mobile devices and the Web.
Nowadays, HTTP has emerged as the mainstream transport protocol, and it is extensively used to communicate between clients (from web browsers, of course, but also from desktop and mobile applications, backend services, etc.) and web servers. It has replaced almost all proprietary or nonstandard protocols and is likely to be the de facto choice if your application needs to communicate with any remote endpoint.
Messaging protocols complement HTTP, and this book focuses on cases in which a messaging protocol is better suited than HTTP (or any other request/reply transport protocol) to build mobile or web applications.
What This Book is Not About
Messaging is an overloaded term that can mean many different things in software development. In this book, we will only talk about application messaging protocols.
This book is not about messaging applications like Apples Messages or WhatsApp. These applications can be built on top of messaging protocols and this book may be a good introduction if you intend to build one. However, many other features are expected in messaging applications that will not be covered in this book.
This book is also not about programming language or framework messaging (as used in Objective-C to invoke methods on an object or in Erlang to communicate between processes).
Note
In the rest of this book, we will use the term
messaging in the context of application messaging protocol.
Messaging is Simple
At its core, the concept of a messaging protocol is simple:
In these two sentences, I introduced the five concepts that are (almost) all there is to know about messaging.
A messaging protocol is a simple idea. Most of the complexity of using one is figuring out the best model for your applications (how the producers and consumers will exchanges messages). This book will show the two most commonly used models: point-to-point and publish/subscribe.
Enterprise Messaging Is Not So Simple
When companies are acquired or merged, they need a way to enable communication between their systems. Messaging is one approach to achieve this integration in an unobstrusive way (as much as possible). The systems must agree on the data representation (transmitted in the message) and the destination (or the topic of interest shared by the different systems).
With its use in enterprise software, messaging protocols became increasingly complex in order to meet enterprise requirements (high availability, failover, load balancing, etc.).
In addition, the integrated applications must often agree on a messaging system to use throughout the company. In the Java world, the specification that deals with messaging is called Java Messaging Service. It defines a set of interfaces that a Java application can use to send and receive messages. However, JMS does not define any protocol (how the bytes are sent over the wire); instead, it leaves this implementation detail to the JMS brokers that implement the API. This means that JMS implementations are not interoperable: one must use the brokers client implementation to send a message to the broker. If applications were using different JMS brokers, they had interoperability issues and must use bridges to transfer messages from one JMS broker to another. This lack of interoperability brings complexity, as you need to add servers to host the bridges, make them redundant for high availability, and so on.
Over time, we have seen the appearances of enterprise messaging protocols such as the Advanced Message Queuing Protocol, which handles enterprise features and interoperability. This leads to complex protocols that are difficult to implement and whose interoperability is subjective (backward compatibility is not guaranteed, different implementations may not implement the whole specification leading to interoperability issues).