0
0
RabbitMQdevops~20 mins

Publisher confirms in RabbitMQ - Mini Project: Build & Apply

Choose your learning style9 modes available
RabbitMQ Publisher Confirms Basics
📖 Scenario: You are building a simple messaging system where a publisher sends messages to a RabbitMQ queue. To ensure messages are safely received by the broker, you will use Publisher Confirms. This helps you know if your messages were successfully handled.
🎯 Goal: Create a RabbitMQ publisher that sends messages with publisher confirms enabled. You will set up the connection, enable confirms, publish a message, and handle the confirmation callback to print success or failure.
📋 What You'll Learn
Create a connection and channel to RabbitMQ
Enable publisher confirms on the channel
Publish a message to a queue named task_queue
Add a confirmation callback to print Message confirmed on success
Print Message NOT confirmed on failure
💡 Why This Matters
🌍 Real World
Publisher confirms are used in real messaging systems to guarantee that messages are not lost and are safely received by the broker before proceeding.
💼 Career
Understanding publisher confirms is important for DevOps and backend engineers working with message queues to build reliable, fault-tolerant systems.
Progress0 / 4 steps
1
Setup RabbitMQ connection and channel
Create a connection to RabbitMQ on localhost and open a channel named channel.
RabbitMQ
Need a hint?

Use pika.ConnectionParameters('localhost') to connect locally.

2
Enable publisher confirms on the channel
Enable publisher confirms on the channel by calling channel.confirm_delivery().
RabbitMQ
Need a hint?

Call confirm_delivery() on the channel to enable confirms.

3
Publish a message with confirmation handling
Publish the message 'Hello RabbitMQ!' to the queue 'task_queue' using channel.basic_publish. Use a try-except block to catch pika.exceptions.UnroutableError and print 'Message NOT confirmed' if it occurs. Otherwise, print 'Message confirmed' after publishing.
RabbitMQ
Need a hint?

Use basic_publish with exchange='' and routing_key='task_queue'. Wrap in try-except to catch UnroutableError.

4
Close connection and print final confirmation
Close the connection after publishing and confirmation. The program should print exactly Message confirmed if the message was accepted by RabbitMQ.
RabbitMQ
Need a hint?

Call connection.close() to cleanly close the connection.