0
0
RabbitMQdevops~5 mins

AMQP protocol overview in RabbitMQ - Commands & Configuration

Choose your learning style9 modes available
Introduction
AMQP is a way for programs to send messages to each other safely and reliably. It helps different parts of a system talk without losing messages or getting confused.
When you want to send tasks from a web app to a background worker without losing any tasks.
When multiple services need to share information quickly and reliably.
When you want to make sure messages are delivered even if one part of the system is temporarily down.
When you want to balance work between several workers automatically.
When you want to keep messages organized by topic or category.
Commands
This command checks if RabbitMQ server is running and shows its status.
Terminal
rabbitmqctl status
Expected OutputExpected
Status of node rabbit@localhost ... [{pid,12345}, {running_applications,[ {rabbit,"RabbitMQ","3.11.14"}, {os_mon,"CPO CXC 138 46","2.4"}, {mnesia,"MNESIA CXC 138 12","4.18"} ]}, {os,{unix,linux}}, {memory,[{total,104857600}]}, {alarms,[]}]
This command lists all queues currently available in RabbitMQ with their message counts.
Terminal
rabbitmqctl list_queues
Expected OutputExpected
Listing queues ... queue1 0 queue2 5
This command creates a direct exchange named 'my-exchange' where messages can be sent to specific queues.
Terminal
rabbitmqadmin declare exchange name=my-exchange type=direct
Expected OutputExpected
Success
This command creates a durable queue named 'my-queue' that will survive server restarts.
Terminal
rabbitmqadmin declare queue name=my-queue durable=true
Expected OutputExpected
Success
This command binds the queue 'my-queue' to the exchange 'my-exchange' with the routing key 'my-key' so messages with this key go to this queue.
Terminal
rabbitmqadmin declare binding source=my-exchange destination=my-queue routing_key=my-key
Expected OutputExpected
Success
Key Concept

If you remember nothing else from AMQP, remember: it safely routes messages between producers and consumers using exchanges and queues.

Common Mistakes
Not binding a queue to an exchange after creating them
Messages sent to the exchange won't reach any queue without a binding.
Always create a binding between exchange and queue with the correct routing key.
Creating non-durable queues for important messages
Non-durable queues lose messages if RabbitMQ restarts.
Use durable queues for messages that must survive server restarts.
Assuming messages are delivered without confirming publish
Without publisher confirms, messages might be lost silently.
Enable publisher confirms to ensure messages are safely received by RabbitMQ.
Summary
Use rabbitmqctl to check RabbitMQ server status and list queues.
Create exchanges and queues to organize message routing.
Bind queues to exchanges with routing keys to direct messages properly.