Quick Introduction to RabbitMQ

Aditi Mittal
Sep 28 · 4 min read

RabbitMQ is a message broker software that implemenets Advanced Message Querying Protocol (AMQP). AMQP is an application layer protocol for message-oriented middleware.

RabbitMQ can be used for performing background operations and performing asynchronous operations. It is also a way to exchange the data between different platform applications.

A message can include any kind of information. The queue-manager software stores the messages until a receiving application connects and takes a message off the queue. The receiving application then processes the message in an appropriate manner.

It can be both micro-services and an app. RabbitMQ support multiple protocols, here are the protocols that RabbitMQ support: AMQP, HTTP, STOMP, MQTT.

RabbitMq has two major components: producers and consumers.

Producer and Consumer

Producers create the messages and deliver them to the broker (or message queue). Consumers connects to the queue and subscribes to the messages to be processed. Messages placed onto the queue are stored until the consumer retrieves them.

The consumer can take a message of the queue and start processing at the same time as the producer is queueing up new messages on the queue. The consumer can be on a totally different server than the publisher, or they can be located on the same server. The request can be created in one programming language and handled in another programming language — the two applications will only communicate through the messages they are sending to each other. Due to that, the two applications will have a low coupling between the sender and the receiver.

Exchanges

Messages are not published directly to a queue, instead, the producer sends messages to an exchange. An exchange is responsible for the routing of the messages to the different queues. An exchange accepts messages from the producer application and routes them to message queues with the help of bindings and routing keys. A binding is a link between a queue and an exchange. The Routing key is a message attribute.

Types of Exchanges

  • Direct: A direct exchange delivers messages to queues based on a message routing key. In a direct exchange, the message is routed to the queues whose binding key exactly matches the routing key of the message.
  • Fanout: A fanout exchange routes messages to all of the queues that are bound to it.
  • Topic: The topic exchange does a wildcard match between the routing key and the routing pattern specified in the binding.
  • Headers: Headers exchanges use the message header attributes for routing.

Benefits of RabbitMQ

— Delivery and order guarantee: The messages have been sent to a consumer in the same order in which they were created.

— Redundancy: The queues persist the messages until they are processed completely.

— Decoupling: Any third party system can consume the messages and interact with them, so you want the messages to be processed by someone who is not the actor who created the message, without any problems. This generates us a benefit, which is that it can be reused for many projects.

— Scalability: we can have an application server dedicated to the processes and the other servers for browsing the web.

Federated Exchange

A federated exchange links to other exchanges known as upstream exchanges. The messages published to the upstream exchanges are copied to the federated exchange, as though they were published directly to it. The upstream exchanges do not need to be reconfigured and they do not have to be on the same broker or in the same cluster.

The federated exchange will connect to all its upstream exchanges using AMQP. When declaring or configuring the federated exchange each upstream exchange is listed with the connection properties to be used to establish the link.

Installation

Before installing make sure the taps are up-to-date:

brew update

Then, install RabbitMQ server with:

brew install rabbitmq

The RabbitMQ server scripts and CLI tools are installed in sbin directory under /usr/local/Cellar/rabbitmq, which is accessible via /usr/local/opt/rabbitmq/sbin. In case that directory is not in PATH it’s recommend to append it:

export PATH=$PATH:/usr/local/opt/rabbitmq/sbin

The server can then be started with rabbitmq-server. With Homebrew the node and CLI tools will use the logged in user account by default. Using sudo is not required.

You can start the RabbitMQ using the following command on the terminal

brew services start rabbitmq       //start
brew services stop rabbitmq //stop
brew services restart rabbitmq //restart

You can access RabbitMQ using URL https://localhost:15672 . The default Username and password of is “guest” (Username: “guest” | Password: “guest”). You can add exchanges and queues through the UI directly.

RabbitMQ can also be accessed using client libraries for different programming languages.

RabbitMQ Supported Client Libraries

RabbitMQ will support multiple operating systems and programming languages. RabbitMQ has provided a various client libraries for following programming languages.

  • .Net
  • Java
  • Spring Framework
  • Ruby
  • Python
  • PHP
  • Objective-C and Swift
  • JavaScript
  • GO
  • Perl

Aditi Mittal

Written by

Machine Learning | Software Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade