Professional Documents
Culture Documents
Getting Started With RabbitMQ and CloudAMQP
Getting Started With RabbitMQ and CloudAMQP
OPTIMAL
RABBITMQ
GUIDE
FROM BEGI
NNER
TO ADVANCED
BYL
OVI
SAJOHANSSON
Acknowledgments
I want to say a big thank you to everyone who has helped me, from the earliest draft of this
book, up to this first edition. A special thanks go out to my lovely colleagues at 84codes
and to my computer nerd (and IRL) friends; Emil, Filip, Lisa, and Thomas.
Finally: A big thank you, to all Cloud.AMQP users for your feedback and continued
support. It has been a great motivator to see our customers' projects succeed!
ISBN: 978-91-639-9585-9
Author: Lovisa Johansson
Email: lovisa@cloudamqp.com
Published: 2018-10-25
Graphics: Elin Vinka, Daniel Marklund
•
This book is dedicated to all the frequent and future users ofRabbitMQ, and to the Swedish
mentality that made us queue lovers by heart.
Table of Contents
Times are changing! Reliability and scalability are more important than ever. Because of that com
panies are rethinking their architecture. Monoliths are evolving into microservices and servers are
moving into the cloud. Message Queues and RabbitMQ, one of the most widely deployed open
source message brokers, has come to play a significant role in the growing world of microservices.
The first part focuses on giving a gentle introduction to microservices and RabbitMQ, and how to
use RabbitMQ on the CloudAMQP online platform. You will learn the most important RabbitMQ
concepts and how RabbitMQ allows users to create products that match all of the demands made
by the industry of both today and tomorrow.
The second part of the book is for the more advanced users. You will, after this part, be able to take
full advantage of RabbitMQ. We talk about Best Practice recommendations for High Performance
and High Availability and common RabbitMQ errors and mistakes. It's also a deep dive into some
RabbitMQ concepts and features.
The third part gives some real-world user stories from own experiences and a CloudAMQP cus
tomer's point of view.
We hope that this book will help to take you even further on your message queuing journey.
9
Microservices and RabbitMQ
In a microservice architecture (also called modular architecture) different modules are de-coupled
from each other. These modules often offer various functionalities, forming a complete software
application, via properly articulated operations and interfaces. Unlike a monolithic application,
where all chunks of functionality are present within a single module, a microservice application
divides different functionalities across different modules, to enhance maintainability and ease-of
use. More and more organizations are going down the microservices road because it allows them to
have a more agile approach to software development and maintenance. Microservices also make it
easy for businesses to scale and deliver updated versions of software weekly, instead of yearly.
11
billing services will still be up, ensuring that your customers can perform important transactions
even when they aren't able to view reports.
♦ Improved scalability
Microservices also allow you to scale effortlessly and at will. If you want to add new components
to just one service, you can do that without changing any of the other services. You can also de
ploy the more resource-intensive services across multiple servers.
♦ Easy to understand
Another advantage offered by a microservice application is the ease of understandability. Since
each module represents a single functionality, getting to know the relevant details becomes easi
er and faster. For example, if you have hired a consultant for your charging services, they don't
have to understand the whole system in order to offer you insight; they only have to familiarize
themselves with one module to do so.
www.cloudamqp.com
Custom Alarms• Free Plan Available• Easy Monitoring • 24/7 support• 99.95% SLA
12
What is RabbitMQ?
13
3. Declare/create a queue. Declaring a queue will cause it to be created if it does not already
exist. All queues need to be declared before they can be used.
4. Set up exchanges and bind a queue to an exchange. Messages are only routed to a queue if
the queue is bound to an exchange.
5. Publish a message to an exchange, and consume a message from the queue.
6. Close the channel and the connection.
Sample code
Sample code for Ruby, Node.js, and Python can be found in upcoming chapters. It's possible to use
different programming languages in different parts of your system. The subscriber could, for ex
ample, be written in Node.js while the subscriber is written in Python.
www.cloudamqp.com
Custom Alarms • Free Plan Available • Easy Monitoring • 24/7 support• 99.95% SLA
21
Open the management interface for the downstream server (EU-West-1) and go to the Admin ->
Federation Upstreams screen and press Add a new upstream (figure 42). Fill in all information
needed, the URI should be the URI of the upstream server.
Leave expiry time and TIL blank. Leaving this blank means that it will stay forever.
It's time to connect or move the publisher or the consumer to the new cluster. If you are migrating
the cluster, you can move the publisher and/or the consumer in any order. The federated queue
will only retrieve messages when it has run out of messages locally when it has consumers that
need messages, or when the upstream queue has "spare" messages that are not being consumed.
Verify that the downstream server consumes the messages published to the queue at the upstream
server when there are consumers available at the downstream server. If it does, then we are done.
www.cloudamqp.com
Custom Alarms• Free Plan Available• Easy Monitoring • 24/7 support• 99.95% SLA
Bo
}, msg);
function onError(e) {
console.log("STOMP ERROR", e);
function onDebug(m) {
console.log("STOMP DEBUG", m);
www.cloudamqp.com
Custom Alarms• Free Plan Available• Easy Monitoring • 24/7 support• 99.95% SLA
85
A dedicated RabbitMQ instance can be created via the CloudAMQP control panel, or by adding the
CloudAMQP add-on from any of our integrated platforms, like Heroku, IBM Cloud Catalogue,
AWS marketplace, Azure marketplace, Manifold just to mention a few.
Q OPENSHIFT 'ttcloudAMQP
®
0 Google Cloud Platform
RobbitMQ [ mgmt-shovel I
:I Windows·Azure· [ server-metrics]
0 DigitalOcean ssh-monitor
(3 rockspace.
SOFTLAY:R'
�[
'--------------------
machine ]
When a client creates a new dedicated instance, an HTIP request is sent from the reseller to a ser
vice called CloudAMQP-API (1). The HTIP request includes all information specified by the client:
plan, server name, data center, region, number of nodes etc., as you see in the picture above.
CloudAMQP-API handles the request, save information into a database (2), and finally, send a ac
count.create-message to one of our RabbitMQ-clusters (3).
CloudAMQP-machine trigger a whole lot of scripts and processes. First, it creates the new server(s)
in the chosen datacenter via an HTIP request (5). We use different underlying instance types de
pending on data center, plan and number of nodes. CloudAMQP-machine is responsible for all
configuration of the server, setting up RabbitMQ, mirror nodes, handle clustering for RabbitMQ
etc., all depending on the number of nodes and chosen datacenter.
91
This section described a small part of the CloudAMQP service. We do in total have around 100 mi
croservices, all communicating via CloudAMQP and RabbitMQ.
I hope you enjoyed the reading and that you at least learned someting new. Never hesitate to send
me an email!
www.cloudamqp.com
Custom Alarms• Free Plan Available• Easy Monitoring • 24/7 support• 99.95% SLA
93