34,79 €
RabbitMQ is an open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover. Messaging enables software applications to connect and scale. Applications can connect to each other as components of a larger application or to user devices and data.
RabbitMQ Cookbook touches on all the aspects of RabbitMQ messaging. You will learn how to use this enabling technology for the solution of highly scalable problems dictated by the dynamic requirements of Web and mobile architectures, based for example on cloud computing platforms. This is a practical guide with several examples that will help you to understand the usefulness and the power of RabbitMQ.
This book helps you learn the basic functionalities of RabbitMQ with simple examples which describe the use of RabbitMQ client APIs and how a RabbitMQ server works. You will find examples of RabbitMQ deployed in real-life use-cases, where its functionalities will be exploited combined with other technologies. This book helps you understand the advanced features of RabbitMQ that are useful for even the most demanding programmer. Over the course of the book, you will learn about the usage of basic AMQP functionalities and use RabbitMQ to let decoupled applications exchange messages as per enterprise integration applications. The same building blocks are used to implement the architecture of highly scalable applications like today's social networks, and they are presented in the book with some examples. You will also learn how to extend RabbitMQ functionalities by implementing Erlang plugins.
This book combines information with detailed examples coupled with screenshots and diagrams to help you create a messaging application with ease.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 290
Veröffentlichungsjahr: 2013
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2013
Production Reference: 1171213
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-650-1
www.packtpub.com
Cover Image by Sandeep Vaity (<[email protected]>)
Authors
Sigismondo Boschi
Gabriele Santomaggio
Reviewers
Lucas Hrabovsky
Jorge Puente Sarrín
Ken Taylor
Ignacio Colomina Torregrosa
Héctor Veiga
Acquisition Editors
Usha Iyer
Llewellyn Rozario
Lead Technical Editor
Chalini Snega Victor
Copy Editors
Alisha Aranha
Roshni Banerjee
Dipti Kapadia
Karuna Narayanan
Kirti Pai
Shambhavi Pai
Alfida Paiva
Laxmi Subramanian
Technical Editors
Shubhangi Dhamgaye
Novina Kewalramani
Pratik More
Suneeth Nair
Rohit Kumar Singh
Project Coordinator
Anugya Khurana
Proofreader
Linda Morris
Indexer
Tejal Soni
Graphics
Ronak Dhruv
Abhinash Sahu
Production Coordinator
Adonia Jones
Cover Work
Adonia Jones
Sigismondo Boschi is a software developer currently involved in projects of messaging and networking distributed applications.
Prior to this, he has had more than 10 years' experience working with distributed applications and message-passing paradigms. He first acquired a PhD in Computational Physical Chemistry from the University of Bologna, and then has worked in the Development of Scientific High Performance Computing Projects.
To my wife, Maria Luisa, and my children, Gaia and Marco.
Gabriele Santomaggio has worked in the IT industry for more than 15 years. He is a developer, and very keen on middleware and distributed applications. Currently, he is working on high-performance Java applications.
He is the member of a big IT Italian community (www.indigenidigitali.com/) where he has published some posts about Amazon Web Services and message-oriented middleware (http://blog.indigenidigitali.com/tag/gabriele-santomaggio/).
He likes running and listening to jazz music.
To my beautiful wife, Dia, and my little ninja turtle, Riccardo, with love.
Jorge Puente Sarrín is a Peruvian software developer, currently working at Red Científica Peruana (RCP) as a software architect designing service-based solutions. He is a passionate developer focused on building distributed systems solutions using asynchronous programming with Python and .NET. Also, he has been contributing towards the translation of documentation projects and online courses into Spanish. He is a proud member of Masters of MongoDB, a group of persons who are promoting MongoDB around the world.
Ken Taylor has worked in software development and technology for over 15 years. During the course of his career, he has worked as a systems analyst on multiple software projects in several industries as well as with the state government. He has used RabbitMQ for messaging on multiple projects as a way of scaling and as an integration point. He is a member and speaker of the 757 Ruby users group and the Hampton Roads .NET users group (HRNUG). Ken holds an A.S. in Computer Science from Paul D. Camp Community College and was awarded a U.S. Patent for a Real Estate financial software product. He is currently working at Outsite Networks Inc. in Norfolk, Virginia. He lives in Suffolk, Virginia with his lovely wife Lucia and his two sons, Kaide and Wyatt.
I would like to thank my wife for her support while writing this book and my sons for reminding me of the importance of being inquisitive. Thank you Packt Publishing for asking me to participate as a technical reviewer for this excellent resource on RabbitMQ.
Ignacio Colomina Torregrosa is a technical engineer in telecommunications and a master in free software. He works as a PHP/Symfony developer and has had experience using RabbitMQ as a tool to optimize and improve the performance of web applications that deal with large amounts of traffic.
Héctor Veiga is a software engineer specializing in real-time data integration. Recently, he has focused his work on different cloud technologies (AWS, Heroku, OpenShift, and so on) to develop scalable, resilient, and high-performing applications that are able to handle high-volume, real-time data in diverse protocols and formats. Additionally, he has a strong knowledge of messaging systems, such as RabbitMQ and AMQP. Also, Héctor has a Master's degree in Telecommunication Engineering from the Universidad Politécnica de Madrid and a Master's degree in Information Technology and Management from the Illinois Institute of Technology.
Héctor currently works at HERE as part of Global Data Integration team and is actively developing scalable applications to consume data from several different sources. HERE heavily utilizes RabbitMQ to address their messaging requirements. In the past, Héctor has worked at Xaptum Technologies, a company dedicated to M2M technologies.
I would like to thank my family and friends for their support. They showed me that giving up was not an option and that you just need to keep pushing. Also, I am greatly thankful for the opportunity I was given to live and work in a foreign country. Finally, I would like to acknowledge Steve Fosdal who has been my friend and RabbitMQ colleague during this journey.
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
The RabbitMQ Cookbook covers RabbitMQ and the corresponding AMQP protocol.
Even the less-experienced programmer can find a lot of information that is useful to start developing messaging applications using RabbitMQ, especially in the first few chapters.
However, in order to fully appreciate some of the chapters of the book, the reader should also know the basic concepts about web and cloud applications.
The book is full of examples that show you how to use RabbitMQ in very disparate scenarios, in different technologies, right from single hosts to geographically replicated high-availability clusters. Mostly everyone working with these technologies will find a lot of useful information within this book.
Chapter 1, Working with AMQP, introduces the basic concepts of AMQP, the Advanced Message Queuing Protocol, on which RabbitMQ is based. It shows how the fire-and-forget messaging model works and how to use it from clients.
Chapter 2, Going beyond the AMQP Standard, covers the RabbitMQ extensions of AMQP and how they can be used to increase the efficiency of messaging applications.
Chapter 3, Managing RabbitMQ, explains how to configure RabbitMQ parameters, enable RabbitMQ plugins, and monitor RabbitMQ activities.
Chapter 4, Mixing Different Technologies, covers the integration of different technologies with other protocols, such as MQTT, STOMP, and JSON.
Chapter 5, Using RabbitMQ in Web Applications, shows how to develop web applications with RabbitMQ as a service bus.
Chapter 6, Developing Scalable Applications, explains how to create scalable and robust applications using RabbitMQ clustering.
Chapter 7, Developing High-availability Applications, covers the high-availability options offered by RabbitMQ.
Chapter 8, Performance Tuning for RabbitMQ, explains how to optimize the performance of applications based on RabbitMQ in different scenarios.
Chapter 9, Extending RabbitMQ Functionality, covers the use and development of RabbitMQ plugins.
Chapter 10, RabbitMQ on AWS, explains how to deploy RabbitMQ applications on Amazon Web Services.
Chapter 11, AMQP and Cloud Computing – RabbitMQ on PaaS, explains how to deploy and use RabbitMQ on Cloud Foundry.
Chapter 12, Managing RabbitMQ Error Conditions, explains how to diagnose and deal with RabbitMQ error conditions.
You can use Linux/Unix, Mac OS X, or Windows as the operating system since RabbitMQ is cross-platform middleware. Most of the examples have been developed in Java, but to execute other recipes, you will also need:
The RabbitMQ Cookbook also covers the cloud computing world (both IaaS and PaaS). To utilize the respective chapters, you will need an account on:
The RabbitMQ Cookbook is for software developers who want to develop distributed applications based on messaging. It’s assumed that the reader has some experience with multithreaded applications and distributed applications.
The reader should also know the basic concepts of web and cloud applications in order to follow the recipes specifically.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
In this chapter we will cover:
Advanced Message Queuing Protocol (AMQP) has been developed because of the need for interoperability among the many different messaging solutions, that were developed a few years ago by many different vendors such as IBM MQ-Series, TIBCO, or Microsoft MSMQ.
The AMQP 0-9-1 standard gives a complete specification of the protocol, particularly regarding:
RabbitMQ is a free and complete AMQP broker implementation. It implements version 0-9-1 of the AMQP specification; this is the most widespread version today and it is the last version that focuses on the client API. That's what we want to put the focus on, especially in this chapter.
On the other hand, AMQP 1.0 only defines the evolution of the wire-level protocol—the format of the data being passed at the application level—for the exchange of messages between two endpoints; so 0-9-1 is actually the most updated client library specification.
RabbitMQ includes:
It is also possible to use APIs for languages downloadable from the RabbitMQ site itself, from third-party sites, or even using AMQP APIs not strictly related to RabbitMQ (http://www.rabbitmq.com/devtools.html). Since the AMQP standard specifies the wire protocol, they are going to be mostly interoperable, except for some custom extensions. That will be discussed in detail in the next chapter.
In the course of the book we will particularly use some of the following APIs:
In this first chapter we are mainly using Java since this language is widely used in enterprise software development, integration, and distribution. RabbitMQ is a perfect fit in this environment.
In order to run the examples in this recipe, you will first need to:
The natural choice is to install it on your desktop (Windows, Linux, and Mac OS X are all fine choices), but you can also install it on one or more external servers; for example, virtual machines, physical servers, and Raspberry PI servers (http://www.raspberrypi.org/) on cloud service providers.
In this book we are not providing instructions on the installation of RabbitMQ itself. You can find detailed instructions on the RabbitMQ site.
Most of the examples will work connecting to the RabbitMQ broker running on the localhost. If you have chosen to install or use RabbitMQ from a different machine, you will need to specify its hostname as a command-line parameter of the examples themselves, for example:
For the examples involving Python, you will need Python 2.7+ installed and the Pika library, an AMQP implementation for Python (https://pypi.python.org/pypi/pika). The fastest way to install Pika is by using PIP (https://pypi.python.org/pypi/pip). In the command prompt, just type:
We will also present some recipes using .NET where the accent is mainly on interoperability.
You can download the working examples in their full form at http://www.packtpub.com/support.
The recipes presented in this chapter will tackle all the basic concepts exposed by AMQP, using RabbitMQ.