Companies are now shifting towards the adoption of microservice-based architecture in modern applications. To handle and distribute the workload for smooth and fast functioning of the application, using decoupled modules became a necessity. Message brokers allow applications to communicate and decouple from each other.
RabbitMQ is a widely used open-source message broker that helps in scaling the application by deploying a message queuing mechanism in between the two applications. It offers temporary storage for data preventing data loss. RabbitMQ Queue takes messages from the publisher and sends them to the consumer.
RabbitMQ works as an intermediary platform that ensures the message is delivered to the right destination. In this article, you will learn about RabbitMQ, its basic terminologies, and how to message through RabbitMQ. You will also go through the steps to create a Python program to send messages through RabbitMQ Queue.
RabbitMQ is an open-source message broker software written in Erlang. It is commonly called message-oriented middleware that implements the AMQP (Advanced Message Queuing Protocol). It is extended with a plug-in architecture to provide support for MQ Telemetry Transport (MQTT), Streaming Text Oriented Messaging Protocol (STOMP), and other protocols. RabbitMQ is highly scalable and ensures data availability all the time with fault-tolerant architecture.
RabbitMQ supports many programming languages and can run on various Cloud environments and operating systems. It offers browser-based UI for monitoring and management, and also comes with HTTP UI and CLI tools for operations. RabbitMQ is lightweight and easy to deploy on Cloud and premises. Moreover, it can be deployed in distributed as well as federated configurations to provide high scalability and availability to meet business requirements.
Basic concepts of RabbitMQ:
Some of the main features of RabbitMQ are listed below:
To learn more about RabbitMQ, click here.
Simplify Data Streaming Using Hevo’s No Code Data PipelineHevo Data, an Automated No Code Data Pipeline, a Fully-managed Data Pipeline platform, can help you automate, simplify & enrich your data replication process in a few clicks. With Hevo’s wide variety of connectors and blazing-fast Data Pipelines, you can extract & load data from 100+ data sources straight into your Data Warehouse or any Databases. To further streamline and prepare your data for analysis, you can process and enrich raw granular data using Hevo’s robust & built-in Transformation Layer without writing a single line of code!
Get Started with Hevo for FreeHevo is the fastest, easiest, and most reliable data replication platform that will save your engineering bandwidth and time multifold. Try our 14-day full access free trial today to experience an entirely automated hassle-free Data Replication!
What is RabbitMQ Queue?A RabbitMQ Queue is a sequential data structure in which an item can be enqueued at the last or dequeued from the head. Publishers and Consumers communicate using a queue-like storage mechanism. RabbitMQ Queues follows FIFO (First in First out) but it also offers other queue features such as priorities and re-queueing for changing the order.
RabbitMQ Queues have names so that applications can reference them. The application picks a RabbitMQ Queue by name or asks the broker to generate a name to distinguish 2 RabbitMQ queues from each other.
Properties of RabbitMQ QueueRabbitMQ Queues have properties that define how they behave. There are a few mandatory as well as optional properties of RabbitMQ Queue, listed below:
In this section, you will learn how the message flow RabbitMQ takes place. The following procedure is given below:
Now that you have understood what RabbitMQ is, its basic terminologies, and how messages flow through RabbitMQ Queue. In this section, you will go through the process to send messages through RabbitMQ using Python. The following steps to send a message through RabbitMQ are listed below:
For this tutorial, the Pika Python client which is a Python library will be used. Here, you need to write two programs: one for sending messages and the other for receiving messages. The producer or sender will send the message and RabbitMQ Queue will keep the message as a buffer on behalf of the consumer and then send the message to the consumer.
Sending Messagepython -m pip install pika --upgrade
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue=’queue1’)
channel.basic_publish(exchange='',
routing_key='queue1',
body='Hi, Msg 1')
print(" [x] Sent 'Hi, Msg 1'")
connection.close()
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='queue1')
channel.basic_publish(exchange='', routing_key='queue1', body='Hi, Msg 1')
print(" [x] Sent 'Hi, Msg 1'")
connection.close()
What Makes Hevo’s Data Streaming and Loading UniqueProviding a high-quality ETL solution can be a difficult task if you have a large volume of data. Hevo Data‘s automated, No-code platform empowers you with everything you need to have for a smooth data replication experience.
Check out what makes Hevo amazing:
Want to take Hevo for a spin? Sign Up here for a 14-day free trial and experience the feature-rich Hevo.
Receiving Messageimport pika, sys, os
def main():
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='queue1’)
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(queue=’queue1’,
auto_ack=True,
on_message_callback=callback)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('Interrupted')
try:
sys.exit(0)
except SystemExit:
os._exit(0)
import pika, sys, os
def main():
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='queue1')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(queue=’queue1’, on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('Interrupted')
try:
sys.exit(0)
except SystemExit:
os._exit(0)
python send.py
# => [x] Sent 'Hello World!'
python receive.py
# => [*] Waiting for messages. To exit press CTRL+C
# => [x] Received 'Hi, Msg 1'
That’s it! You have successfully sent a message through the RabbitMQ.
ConclusionIn this article, you learnt about RabbitMQ Queues and Messaging, its essential terminologies such as Producer, Exchange, Consumer, Queue, etc. You also read how message flows through RabbitMQ from producer to consumer and went through the steps to create a Python program to send and receive messages through RabbitMQ. RabbitMQ is the most widely deployed message broker that helps companies develop and manage scalable applications.
It is essential to store these data streams in Data Warehouses and run Analytics on them to generate insights. Hevo Data is a No-code Data Pipeline solution that helps to transfer data from Kafka and 100+ sources to desired Data Warehouse. It fully automates the process of transforming and transferring data to a destination without writing a single line of code.
Want to take Hevo for a spin? Sign Up here for a 14-day free trial and experience the feature-rich Hevo suite first hand.
Share your experience of learning about RabbitMQ Queue and Messaging in the comments section below!
For more information best message queue, please get in touch with us!