0
0
RabbitMQdevops~5 mins

Message queue use cases in RabbitMQ - Commands & Configuration

Choose your learning style9 modes available
Introduction
Message queues help different parts of a system talk to each other without waiting. They let one part send a message and keep working while another part handles it later. This solves problems when tasks take time or systems need to work together smoothly.
When you want to send emails without making users wait for the email to be sent.
When you need to process orders in an online store one by one without losing any.
When different services in your app need to share data but run on different servers.
When you want to balance work between many workers so no one is overloaded.
When you want to keep tasks safe even if one part of your system crashes.
Commands
Check if RabbitMQ server is running and get 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"}]}, {os,{unix,linux}}, {memory,[{total,104857600},{connection_readers,123456},{connection_writers,123456}]}]
Create a durable queue named 'my-queue' that keeps messages safe even if RabbitMQ restarts.
Terminal
rabbitmqadmin declare queue name=my-queue durable=true
Expected OutputExpected
Successfully declared queue 'my-queue'
durable=true - Makes the queue survive server restarts
Send a message with the text 'Hello, world!' to the queue 'my-queue'.
Terminal
rabbitmqadmin publish routing_key=my-queue payload='Hello, world!'
Expected OutputExpected
Published message to queue 'my-queue'
Retrieve one message from 'my-queue' without putting it back after reading.
Terminal
rabbitmqadmin get queue=my-queue requeue=false
Expected OutputExpected
Message: { "payload": "Hello, world!", "payload_bytes": 13, "redelivered": false, "exchange": "", "routing_key": "my-queue" }
requeue=false - Prevents the message from returning to the queue after reading
Key Concept

If you remember nothing else from this pattern, remember: message queues let parts of your system work independently and safely by passing messages asynchronously.

Common Mistakes
Creating queues without durability when messages must not be lost
Messages and queues will be lost if RabbitMQ restarts, causing data loss
Always set durable=true for queues that must keep messages safe across restarts
Not acknowledging messages after processing
Messages may be lost or reprocessed unexpectedly, causing errors or duplicates
Use manual acknowledgments to confirm message processing before removing them from the queue
Sending messages directly to queues without using exchanges
Limits routing flexibility and scalability in complex systems
Use exchanges to route messages to queues based on rules for better control
Summary
Use 'rabbitmqctl status' to check if RabbitMQ is running.
Create durable queues to keep messages safe with 'rabbitmqadmin declare queue'.
Send messages to queues using 'rabbitmqadmin publish'.
Retrieve messages safely with 'rabbitmqadmin get' and control requeue behavior.