-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPreface.html
264 lines (188 loc) · 23.4 KB
/
Preface.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<section data-type="preface" id="_preface" xmlns="http://www.w3.org/1999/xhtml">
<h1>Preface</h1>
<p>The use of small smart devices is increasing and widening. <a contenteditable="false" data-primary="smart devices, widening use of" data-type="indexterm"> </a>Smartphones and tablets are connected to the Internet—and 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.</p>
<p>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.<a contenteditable="false" data-primary="messaging" data-secondary="overcoming constraints of smart devices" data-type="indexterm"> </a></p>
<p>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.</p>
<p>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.</p>
<p>This book provides an introduction to the messaging protocols to help software developers use them in mobile and web applications.</p>
<section data-type="sect1" id="_what_this_book_is_about">
<h1>What This Book is About</h1>
<p>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.</p>
<p>Messaging protocols are nothing new.<a contenteditable="false" data-primary="messaging protocols" data-type="indexterm"> </a> 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.</p>
<p>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.<a contenteditable="false" data-primary="HTTP, messaging protocols and" data-type="indexterm"> </a> 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.</p>
<p>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.</p>
</section>
<section data-type="sect1" id="_what_this_book_is_em_not_em_about">
<h1>What This Book is Not About</h1>
<p><em>Messaging</em> is an overloaded term that can mean many different things in software development. In this book,<a contenteditable="false" data-primary="application messaging protocols" data-type="indexterm"> </a> we will only talk about <em>application messaging protocols</em>.</p>
<p>This book is not about <em>messaging applications</em> like Apple’s 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.</p>
<p>This book is also not about <em>programming language or framework messaging</em> (as used in Objective-C to invoke methods on an object or in Erlang to communicate between processes).</p>
<div data-type="note">In the rest of this book, we will use the term <em>messaging</em> in the context of application messaging protocol.</div>
</section>
<section data-type="sect1" id="_messaging_is_simple">
<h1>Messaging is Simple</h1>
<p>At its core, the concept of a messaging protocol is simple:</p>
<ul>
<li>
<p>An application <em>produces</em> a <em>message</em> to a <em>destination</em> on a <em>broker</em>.</p>
</li>
<li>
<p>An application subscribes to this same destination to <em>consume</em> the message.</p>
</li>
</ul>
<p>In these two sentences, I introduced the five concepts that are (almost) all there is to know about messaging.</p>
<p>A messaging protocol is a simple idea. Most of the complexity of using one is figuring out the best <em>model</em> for your applications (how the producers and consumers will exchanges messages).<a contenteditable="false" data-primary="models, messaging" data-type="indexterm"> </a> This book will show the two most commonly used models: <em>point-to-point</em> and <em>publish/subscribe</em>.</p>
</section>
<section data-type="sect1" id="_enterprise_messaging_is_not_so_simple">
<h1>Enterprise Messaging Is Not So Simple</h1>
<p>When companies are acquired or merged, they need a way to enable communication between their systems. <a contenteditable="false" data-primary="enterprise messaging" data-type="indexterm"> </a>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 <em>message</em>) and the <em>destination</em> (or the topic of interest shared by the different systems).</p>
<p>With its use in enterprise software, messaging protocols became increasingly complex in order to meet enterprise requirements (high availability, failover, load balancing, etc.).</p>
<p>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 <a href="http://bit.ly/jms-spec">Java Messaging Service</a>. <a contenteditable="false" data-primary="Java Messaging Service (JMS)" data-type="indexterm"> </a>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 broker’s client implementation to send a message to the broker. If applications were using different JMS brokers, they had interoperability issues and must use <em>bridges</em> 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.</p>
<p>Over time, we have seen the appearances of enterprise messaging protocols such as the <a href="http://www.amqp.org">Advanced Message Queuing Protocol</a>, which handles enterprise features and interoperability.<a contenteditable="false" data-primary="Advanced Message Queuing Protocol" data-type="indexterm"> </a> 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).</p>
</section>
<section data-type="sect1" id="_mobile_messaging_is_simple_again">
<h1>Mobile Messaging Is Simple Again</h1>
<p>The increasing complexity of messaging protocols used in enterprise software makes them difficult to implement, and they are not best suited for constrained environments<a contenteditable="false" data-primary="mobile devices, messaging protocols for" data-type="indexterm"> </a> such as mobile devices.<a contenteditable="false" data-primary="messaging protocols" data-secondary="for mobile devices" data-type="indexterm"> </a></p>
<p>Mobile devices require messaging protocols with more constrained goals that turn out to be simpler and more efficient to use without draining battery or requiring always-on network connections.</p>
<p>Although these simpler protocols do not provide all the features offered by enterprise-class messaging protocols, they are a good fit for mobile and web platforms.</p>
<p>In this book, I will talk about two of them: STOMP and MQTT.</p>
<p>STOMP really<a contenteditable="false" data-primary="STOMP" data-type="indexterm"> </a> shines for its simplicity if you need to send one text message from any system (operating system, virtual machine, web browser) to another. It is simple enough that a network client such as telnet <em>is</em> a STOMP client.<a contenteditable="false" data-primary="Telnet" data-type="indexterm"> </a></p>
<p>MQTT was created <a contenteditable="false" data-primary="MQTT" data-type="indexterm"> </a>to broadcast data from small devices with low power usage and constrained memory resources. It is well suited for mobile devices, because it preserves battery life and memory.</p>
<p>These protocols are simple to understand and implement. Messaging brokers often provide both of them. For example, a desktop application can use STOMP to send a message and another mobile application can consume the same message using MQTT. The applications are free to use the most appropriate messaging protocol for their needs and rely on the broker implementations for interoperability.</p>
<p>With the advent of mobile devices, we can use these simple messaging protocols to build more reactive, efficient applications. These protocols are available both for mobile and web platforms, so choosing between these two platforms is not constrained by using a messaging protocol.</p>
<p>At the same time, we can leverage these messaging protocols to integrate with legacy systems, too. If the messaging broker also supports an enterprise-class messaging API (such as JMS) or protocols (such as AMQP), we can build mobile and web applications that can consume messages sent from legacy systems.</p>
</section>
<section data-type="sect1" id="_what_s_in_this_book">
<h1>What’s in This Book</h1>
<p>In this book, I will introduce messaging protocols for mobile devices and web applications.</p>
<div class="dlist">
<dl>
<dt class="hdlist">Chapter 1, Introduction</dt>
<dd>
<p>In this chapter, I introduce the concepts of messaging protocols, their models, and message representation. To illustrate the use of messaging protocols on mobile and web platforms, we will build two applications, one using STOMP and the other MQTT. Both applications will come in two parts—one will run on mobile devices, the other inside a web browser; they will communicate using messages. This chapter explains the overall design of these two example applications.</p>
</dd>
<dt class="hdlist">Chapter 2, Mobile Messaging with STOMP</dt>
<dd>
<p>In this chapter, I present STOMP, a simple text-based messaging protocol. I use StompKit, an iOS library for STOMP, to build the Locations application that sends GPS data from the device and receives text messages.</p>
</dd>
<dt class="hdlist">Chapter 3, Web Messaging with STOMP</dt>
<dd>
<p>In this chapter, I introduce stomp.js, a JavaScript library for STOMP. I'll present a web application that receives messages from the Locations iOS application and displays the collected GPS data on a map. This web application will also send text messages to the iOS application.</p>
</dd>
<dt class="hdlist">Chapter 4, Advanced STOMP</dt>
<dd>
<p>In this chapter, I present the advanced features of STOMP that we did not use when building our applications in Chapters 2 and 3. These advanced features are not always used by messaging applications, but they may prove useful as the applications grow in complexity.</p>
</dd>
<dt class="hdlist">Chapter 5, Beyond STOMP</dt>
<dd>
<p>In this chapter, I discuss features that are not part of STOMP, but are available from some STOMP brokers. These features often help solve common issues and reduce code complexity by leveraging the brokers.</p>
</dd>
<dt class="hdlist">Chapter 6, Mobile Messaging with MQTT</dt>
<dd>
<p>In this chapter, I introduce MQTT, a binary messaging protocol well suited to broadcast data from mobile or embedded devices. We'll take a look at a mobile iOS application, Motions, that uses MQTT to broadcast data about the device motion using the MQTTKit libary and listen for alerts to change the color of the application.</p>
</dd>
<dt class="hdlist">Chapter 7, Web Messaging with MQTT</dt>
<dd>
<p>In this chapter, I use MQTT over Web Sockets to write a web application that communicates with the Motions application to display the device motion data and sends alerts to the devices to change their color.</p>
</dd>
<dt class="hdlist">Chapter 8, Advanced MQTT</dt>
<dd>
<p>In this chapter, I present the advanced features of MQTT that were not used in Chapters 6 and 7.</p>
</dd>
<dt class="hdlist">Appendix A, ActiveMQ</dt>
<dd>
<p>In this appendix, we explain how to install and configure the messaging broker, Apache ActiveMQ messaging broker, which is used in the book to run the STOMP examples.</p>
</dd>
<dt class="hdlist">Appendix B, Mosquitto</dt>
<dd>
<p>In this appendix, we explain how to install and configure the Mosquitto broker and its command-line tools. Mosquitto is used throughout the book to send and receive MQTT messages.</p>
</dd>
</dl>
</div>
<p>The book is organized to be read in order, but some chapters can be skipped depending on your experience. <a data-type="xref" href="ch_introduction">ch_introduction</a> introduces all the concepts discussed throughout the book.</p>
<p>If you are interested in mobile applications, you can focus on Chapters 2 and 6, which present two different messaging protocols for mobile devices. If you are writing web applications, Chapters 3 and 7 are the most relevant.</p>
<p>If you are mainly interested in the STOMP protocol, Chapters 2, 3, 4, and 5 and the most relevant. If you are focused on MQTT, you can read Chapters 6, 7, and 8 instead.</p>
</section>
<section data-type="sect1" id="_target_audience">
<h1>Target Audience</h1>
<p>This book is an introduction to the STOMP and MQTT messaging protocols and assumes no prior experience with them; it also explains in detail the messaging protocols. Each platform’s clients may provide a different API to deal with the protocols, but the underlying concepts remain the same. For both protocols, we will see two different libraries: an Objective-C library for iOS and a JavaScript library for web applications.</p>
<p>Basic programming skills are required. The examples in the book run on different platforms and I have used the programming language that makes the most sense for each of them.</p>
<p>The mobile applications on iOS<a contenteditable="false" data-primary="iOS applications" data-secondary="in Objective-C" data-type="indexterm"> </a> will be written in<a contenteditable="false" data-primary="Objective-C" data-type="indexterm"> </a> Objective-C.<a contenteditable="false" data-primary="mobile applications on iOS" data-type="indexterm"> </a> The graphical application requires minimal knowledge of Xcode and Interface Builder, but all the changes are described step-by-step in the book.</p>
<p>The web applications use the <a contenteditable="false" data-primary="JavaScript" data-type="indexterm"> </a>JavaScript language. <a contenteditable="false" data-primary="web applications" data-secondary="using JavaScript" data-type="indexterm"> </a>We leverage <a href="http://jquery.com">jQuery</a> to make the web applications interactive and manipulate <a contenteditable="false" data-primary="jQuery" data-type="indexterm"> </a>the page elements, but the messaging code is independent of any JavaScript frameworks.</p>
</section>
<section data-type="sect1" id="_conventions_used_in_this_book">
<h1>Conventions Used in This Book</h1>
<p>The following typographical conventions are used in this book:</p>
<div class="dlist">
<dl>
<dt class="hdlist"><em>Italic</em></dt>
<dd>
<p>Indicates new terms, URLs, email addresses, filenames, and file extensions.</p>
</dd>
<dt class="hdlist"><code>Constant width</code></dt>
<dd>
<p>Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.</p>
</dd>
<dt class="hdlist"><strong><code>Constant width bold</code></strong></dt>
<dd>
<p>Shows commands or other text that should be typed literally by the user.</p>
</dd>
<dt class="hdlist"><em><code>Constant width italic</code></em></dt>
<dd>
<p>Shows text that should be replaced with user-supplied values or by values determined by context.</p>
</dd>
</dl>
</div>
<div data-type="tip">
<p>This element signifies a tip, suggestion, or general note.</p>
</div>
<div data-type="warning">
<p>This element indicates a warning or caution.</p>
</div>
</section>
<section data-type="sect1" id="_using_code_examples">
<h1>Using Code Examples</h1>
<p>This book is here to help you get your job done. All contents here are
licensed under <a href="http://bit.ly/cc-nc-nd">Attribution-NonCommercial-NoDerivatives 4.0 International</a>, and we invite the community at large to contribute work including feature requests, typographical error corrections, and enhancements via our <a href="http://bit.ly/mwm-issues">GitHub Issue Tracker</a>. You may reuse any of the text or examples in compliance with
the license, which requires attribution. See full license for details.</p>
<p>Supplemental material (code examples, exercises, etc.) is <a contenteditable="false" data-primary="code examples" data-type="indexterm"> </a>available for download at <a href="https://github.com/mobile-web-messaging/code/"><em class="hyperlink">https://github.com/mobile-web-messaging/code/</em></a>.</p>
<p>The book contains all the code required to run the examples and the general instructions to set up the user interface of the iOS applications.</p>
<p>We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “<em>Mobile and Web Messaging</em> by Jeff Mesnil (O’Reilly). Copyright 2014 Jeff Mesnil, 978-1-491-94480-6.”</p>
<p>If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at <a class="email" href="mailto:[email protected]"><em>[email protected]</em></a>.</p>
</section>
<section data-type="sect1" id="_safari_books_online">
<h1>Safari® Books Online</h1>
<div class="safarienabled">
<p><a class="orm:hideurl:ital" href="https://www.safaribooksonline.com/"><em class="hyperlink">Safari Books Online</em></a> is an on-demand digital library that delivers expert <a class="orm:hideurl" href="http://www.safaribooksonline.com/content">content</a> in both book and video form from the world’s leading authors in technology and business.</p>
</div>
<p>Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.</p>
<p>Safari Books Online offers a range of <a class="orm:hideurl" href="http://www.safaribooksonline.com/subscriptions">product mixes</a> and pricing programs for <a class="orm:hideurl" href="http://www.safaribooksonline.com/organizations-teams">organizations</a>, <a class="orm:hideurl" href="http://www.safaribooksonline.com/government">government agencies</a>, and <a class="orm:hideurl" href="http://www.safaribooksonline.com/individuals">individuals</a>. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens <a class="orm:hideurl" href="http://www.safaribooksonline.com/publishers">more</a>. For more information about Safari Books Online, please visit us <a class="orm:hideurl" href="http://www.safaribooksonline.com/">online</a>.</p>
</section>
<section data-type="sect1" id="_how_to_contact_us">
<h1>How to Contact Us</h1>
<p>Please address comments and questions concerning this book to the publisher:</p>
<ul class="simplelist">
<li>O’Reilly Media, Inc.</li>
<li>1005 Gravenstein Highway North</li>
<li>Sebastopol, CA 95472</li>
<li>800-998-9938 (in the United States or Canada)</li>
<li>707-829-0515 (international or local)</li>
<li>707-829-0104 (fax)</li>
</ul>
<p>We have a web page for this book, where we list errata, examples, and any additional information.<a contenteditable="false" data-primary="web page for this book" data-type="indexterm"> </a> You can access this page at <a href="http://bit.ly/mw-messaging"><em class="hyperlink">http://bit.ly/mw-messaging</em></a>.</p>
<!--Don't forget to update the link above.-->
<p>To comment or ask technical questions about this book, send email to <a class="email" href="mailto:[email protected]"><em>[email protected]</em></a>.</p>
<p>For more information about our books, courses, conferences, and news, see our website at <a href="http://www.oreilly.com"><em class="hyperlink">http://www.oreilly.com</em></a>.</p>
<p>Find us on Facebook: <a href="http://facebook.com/oreilly"><em class="hyperlink">http://facebook.com/oreilly</em></a></p>
<p>Follow us on Twitter: <a href="http://twitter.com/oreillymedia"><em class="hyperlink">http://twitter.com/oreillymedia</em></a></p>
<p>Watch us on YouTube: <a href="http://www.youtube.com/oreillymedia"><em class="hyperlink">http://www.youtube.com/oreillymedia</em></a></p>
</section>
<section data-type="sect1" id="_acknowledgments">
<h1>Acknowledgments</h1>
<p>I’d like to thank the many people who contributed to this book. I hope I have not forgotten anyone, but I probably have.</p>
<p>My colleagues at Red Hat provided help and support in innumerable ways. This list of people is necessarily very incomplete: Bill Burke (I should have listened to you: writing a book is a tiring experience!), Clebert Suconic and Andy Taylor for their messaging expertise, Mark Little for his support. A special thanks to Dimitris Andreadis for his trust and letting me spend part of my work time on this book. Thanks to my teammates in the WildFly and EAP teams (Jason Greene, David M. Lloyd, Brian Stansberry, Kabir Khan, Tomaz Cerar, Emanuel Muckenhuber, and all those I have the pleasure to work with on a daily basis) that helped me lessen my workload so that I could focus on writing this book.</p>
<p>Andy Piper, Clebert Suconic, and Dejan Bosanac helped tremendously by reviewing this book. It is much better thanks to their comments and critics.</p>
<p>The people at O’Reilly were extremely helpful. It was a pleasure working with Allyson McDonald, Nicole Shelby, Rebecca Demarest, Jasmine Kwityn, and Simon St.Laurent.</p>
<p>Thanks to all developers that reported issues on this book and the code examples.</p>
</section>
</section>