0
0
RabbitMQdevops~5 mins

RabbitMQ vs Kafka comparison - CLI Comparison

Choose your learning style9 modes available
Introduction
Sometimes you need to send messages between parts of your app or between different apps. RabbitMQ and Kafka are two popular tools that help with this by moving messages reliably. They solve the problem of making sure messages get delivered and processed in the right way.
When you want to send commands or tasks that need to be processed one by one and in order.
When you need to handle a large stream of data events quickly and keep a history of those events.
When your app parts need to communicate with guaranteed delivery and flexible routing.
When you want to build real-time data pipelines or event-driven systems.
When you want to decouple parts of your system so they can work independently and scale separately.
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,12345678},{processes,2345678}]}, {alarms,[]}, {listeners,[{clustering,25672},{amqp,5672}]}, {vm_memory_high_watermark,0.4}, {disk_free_limit,50000000}, {disk_free,123456789}]
This command lists all Kafka topics available on the Kafka server to check what message streams exist.
Terminal
kafka-topics.sh --bootstrap-server localhost:9092 --list
Expected OutputExpected
example-topic user-events system-logs
--bootstrap-server - Specifies the Kafka server address to connect to.
This command shows all queues in RabbitMQ and how many messages are waiting in each queue.
Terminal
rabbitmqctl list_queues
Expected OutputExpected
Listing queues ... queue_name messages my-queue 5 task-queue 0
This command reads the first 5 messages from the Kafka topic 'example-topic' to see what data is in the stream.
Terminal
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic example-topic --from-beginning --max-messages 5
Expected OutputExpected
message1 message2 message3 message4 message5
--from-beginning - Reads messages from the start of the topic.
--max-messages - Limits the number of messages to read.
Key Concept

If you remember nothing else, remember: RabbitMQ is great for flexible routing and task queues, while Kafka excels at handling large streams of event data with high throughput and persistence.

Common Mistakes
Trying to use RabbitMQ for storing large event logs long-term.
RabbitMQ is designed for message delivery and short-term storage, not for keeping large histories of events.
Use Kafka when you need to keep event data for a long time and replay it.
Using Kafka for simple task queues with complex routing needs.
Kafka does not support advanced routing or message acknowledgments like RabbitMQ does.
Use RabbitMQ when you need flexible routing and guaranteed message processing.
Not checking if the messaging server is running before sending messages.
Messages will fail to send or be lost if the server is down.
Always verify server status with commands like 'rabbitmqctl status' or 'kafka-topics.sh --bootstrap-server localhost:9092 --list' before producing or consuming messages.
Summary
RabbitMQ and Kafka are tools to move messages between parts of an app or different apps.
RabbitMQ is best for task queues and flexible message routing with guaranteed delivery.
Kafka is best for handling large streams of event data with high speed and storing event history.