Book Image

RabbitMQ Essentials

By : David Dossot
Book Image

RabbitMQ Essentials

By: David Dossot

Overview of this book

Table of Contents (17 chapters)

Preface

RabbitMQ is an open source messaging broker that implements the AMQP protocol. In the past few years, its popularity has been growing. Initially used by the most daring companies, many are now discovering not only RabbitMQ's particular virtues, but also the positive impact of using messaging in software engineering. Indeed, with the advent of cloud computing, the need to architect and build systems that both scale and degrade gracefully has become more pressing. Opting for loosely coupled architectures, tied together by a message passing through brokers such as RabbitMQ, software engineers have been able to satisfy the needs of modern application development.

RabbitMQ Essentials takes the readers through the journey of Clever Coney Media, a fictitious company with real-world problems. Starting with their first step of RabbitMQ, we will follow the company as they develop their understanding and usage of messaging across their different applications. From one-way asynchronous message passing to request-response interactions, the reader will discover the wide range of applications that messaging with RabbitMQ enables.

This book covers the core principles of the AMQP protocol and best practices for its usage. It also details some of the proprietary extensions that RabbitMQ has added to the protocol and why and when it makes sense to use them. The interoperability of AMQP is demonstrated throughout the book, with examples written in different programming languages.

This book will teach readers all they need to not only get started with their projects, but also grow them, through gaining a deep and wide understanding of the capacities of RabbitMQ and AMQP. The code has a prominent place in this book, with an accent put on the detailed production-grade examples.

What this book covers

Chapter 1, A Rabbit Springs to Life, introduces the reader to the notion of messaging and its benefits. After introducing AMQP and RabbitMQ, the reader will learn how to install and configure RabbitMQ, and get ready to start developing applications with it.

Chapter 2, Creating an Application Inbox, discusses the usage of RabbitMQ to create a simple message inbox. By the end of this chapter, you'll know how to connect to RabbitMQ and publish direct and topic exchanges and get messages out of queues.

Chapter 3, Switching to Server-push, describes a more efficient way to consume messages and route them to end users. It also introduces the fanout exchange and teaches you how it can be used to reach many queues while publishing only a single message.

Chapter 4, Handling Application Logs, keeps building on the previously learned concepts and puts them in action in the context of aggregating application usage data. You'll also learn about the notion of quality of service and how it can be used to improve performance. You'll perform a load test of your RabbitMQ application.

Chapter 5, Tweaking Message Delivery, discusses the usage of RabbitMQ extensions for the AMQP protocol to make undelivered messages expire and deal with them when this happens. It also discusses the standard options that can be used to ensure the success of message deliveries.

Chapter 6, Smart Message Routing, explains how the headers' exchange can be used to perform a property-based routing of messages and how request-response styles of interactions can be achieved with RabbitMQ.

Chapter 7, Taking RabbitMQ to Production, presents different strategies that can be used to deal with the potential failures of the RabbitMQ broker. In this context, you'll learn about clustering and federation. You'll also read about monitoring RabbitMQ to ensure a smooth production ride.

Chapter 8, Testing and Tracing Applications, describes the challenges that are inherent to distributed systems and what mitigation strategies can be used to alleviate them.

Appendix, Message Schemas, lists all the schemas used to specify the JSON representation of the messages in the different examples.

What you need for this book

Readers with a good command of Java and some knowledge of Ruby and Python will feel the most at ease when reading the code samples. Thus, readers with C, C++, and C# experience should be able to make the most of the Java samples. Finally, the discussion around code samples will benefit all readers, especially those with an exposure to the middleware software engineering.

We will install and configure RabbitMQ as part of the first chapter, so you do not need to worry about this. However, you will need the following software installed before running the code examples:

Who this book is for

This book discusses architectural and programming concepts in the context of messaging; as such, it addresses a wide audience from software architects to engineers. It focuses on building applications with RabbitMQ using different popular programming languages and therefore, contains lot of code. No prior experience with message-oriented middleware is required.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The first of these additions takes care of declaring the topic exchange in the existing onApplicationStart method."

A block of code is set as follows:

rabbitMqManager.call(new ChannelCallable<DeclareOk>()
{
    @Override
    public String getDescription()
    {
        return "Declaring topic exchange: " + USER_TOPICS_EXCHANGE;
    }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    try
    {
        connection = factory.newConnection();
        connection.addShutdownListener(this);
        LOGGER.info("Connected to " + factory.getHost() + ":" + factory.getPort());
    }

Any command-line input or output is written as follows:

$ sudo service rabbitmq-server restart

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "When connected to the management console, click on the Exchanges tab."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

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 , and mention the book title through the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

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.

Customer support

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.

Downloading the example code

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.

Errata

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/support, 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 to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

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 with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.