Bird
Raised Fist0
RabbitMQdevops~20 mins

Consuming messages in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
RabbitMQ Consumer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this RabbitMQ consumer command?
You run this command to consume messages from a queue named task_queue. What output will you see if the queue is empty?
RabbitMQ
rabbitmqadmin get queue=task_queue requeue=false count=1
AMessage received: {"task": "process"}
BError: Queue not found
CNo messages returned
DConnection refused
Attempts:
2 left
💡 Hint
Think about what happens when you try to get a message from an empty queue.
❓ Configuration
intermediate
2:00remaining
Which configuration enables manual message acknowledgment in RabbitMQ consumer?
You want your consumer to manually acknowledge messages after processing. Which consumer configuration option achieves this?
Aauto_ack=false
Bauto_ack=true
Cprefetch_count=0
Ddurable=true
Attempts:
2 left
💡 Hint
Manual acknowledgment means the consumer tells RabbitMQ when a message is done.
🔀 Workflow
advanced
3:00remaining
What is the correct order to consume and acknowledge a message manually?
Arrange these steps in the correct order for a RabbitMQ consumer that manually acknowledges messages.
A3,1,2,4
B1,3,2,4
C2,1,3,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about when you should acknowledge a message.
❓ Troubleshoot
advanced
2:30remaining
Why does this RabbitMQ consumer fail to receive messages?
A consumer is connected but does not receive any messages from the queue. The consumer code uses auto_ack=true and prefetch_count=1. What is the most likely cause?
AThe queue is empty or messages are already acknowledged
Bprefetch_count=1 blocks all messages
Cauto_ack=true prevents message delivery
DThe consumer is not connected to the correct exchange
Attempts:
2 left
💡 Hint
Consider what happens if the queue has no messages or they are already consumed.
✅ Best Practice
expert
3:00remaining
Which practice improves reliability when consuming messages in RabbitMQ?
You want to ensure no messages are lost if your consumer crashes during processing. Which practice is best?
AUse <code>auto_ack=true</code> to speed up processing
BUse manual acknowledgment with <code>auto_ack=false</code> and acknowledge after processing
CSet <code>prefetch_count=0</code> to allow unlimited messages
DUse non-durable queues to avoid message persistence
Attempts:
2 left
💡 Hint
Think about how to avoid losing messages if the consumer crashes.

Practice

(1/5)
1. What is the main purpose of consuming messages in RabbitMQ?
easy
A. To delete messages from the queue without processing
B. To send messages to other applications
C. To receive and process messages sent by other applications
D. To create new queues automatically

Solution

  1. Step 1: Understand message consumption

    Consuming messages means receiving data sent by other apps to react or process it.
  2. Step 2: Identify the purpose

    The main goal is to get messages and handle them, not to send or delete them.
  3. Final Answer:

    To receive and process messages sent by other applications -> Option C
  4. Quick Check:

    Consuming = receiving messages [OK]
Hint: Consuming means receiving messages to process them [OK]
Common Mistakes:
  • Confusing consuming with sending messages
  • Thinking consuming deletes messages without processing
  • Believing consuming creates queues
2. Which of the following is the correct way to start consuming messages using the RabbitMQ Python client?
easy
A. channel.basic_consume(queue='task_queue', on_message_callback=callback_function)
B. channel.basic_publish(queue='task_queue', callback=callback_function)
C. channel.consume_messages(queue='task_queue', callback=callback_function)
D. channel.start_consuming(queue='task_queue', callback=callback_function)

Solution

  1. Step 1: Recall RabbitMQ consume syntax

    The correct method to consume messages is basic_consume with on_message_callback argument.
  2. Step 2: Check options

    channel.basic_consume(queue='task_queue', on_message_callback=callback_function) matches the correct syntax exactly; others use wrong method names or parameters.
  3. Final Answer:

    channel.basic_consume(queue='task_queue', on_message_callback=callback_function) -> Option A
  4. Quick Check:

    Use basic_consume with on_message_callback [OK]
Hint: Use basic_consume with on_message_callback to consume [OK]
Common Mistakes:
  • Using basic_publish instead of basic_consume
  • Wrong method names like consume_messages
  • Passing callback without on_message_callback keyword
3. Given this Python code snippet, what will be printed when a message is received?
def callback(ch, method, properties, body):
    print(f"Received: {body.decode()}")

channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True)
channel.start_consuming()
medium
A. Received: b'hello world'
B. Received: hello world
C. Received: body.decode()
D. Error: callback function missing parameters

Solution

  1. Step 1: Understand callback behavior

    The callback prints the decoded message body as a string using f-string formatting.
  2. Step 2: Decode byte message

    body is bytes, decoded to string 'hello world', so output is 'Received: hello world'.
  3. Final Answer:

    Received: hello world -> Option B
  4. Quick Check:

    Decoded body prints as string [OK]
Hint: Decode message body bytes to string before printing [OK]
Common Mistakes:
  • Printing raw bytes without decoding
  • Printing the string 'body.decode()' literally
  • Missing callback parameters causing errors
4. You wrote this code to consume messages but your callback is never called:
channel.basic_consume(queue='tasks', on_message_callback=callback)
# Missing channel.start_consuming()
What is the most likely reason your callback is not triggered?
medium
A. You forgot to declare the queue before consuming
B. auto_ack must be set to True
C. The callback function has wrong parameters
D. You did not start the consuming loop with start_consuming()

Solution

  1. Step 1: Check consuming process

    After basic_consume, you must call start_consuming() to begin receiving messages.
  2. Step 2: Identify missing call

    The code lacks channel.start_consuming(), so callback never runs.
  3. Final Answer:

    You did not start the consuming loop with start_consuming() -> Option D
  4. Quick Check:

    start_consuming() runs the callback loop [OK]
Hint: Always call start_consuming() after basic_consume [OK]
Common Mistakes:
  • Forgetting to call start_consuming()
  • Assuming auto_ack is required to trigger callback
  • Ignoring queue declaration errors
5. You want to consume messages from a queue and ensure each message is acknowledged only after successful processing. Which code snippet correctly implements this behavior?
hard
A. def callback(ch, method, properties, body): process(body) ch.basic_ack(delivery_tag=method.delivery_tag) channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=False) channel.start_consuming()
B. channel.basic_consume(queue='jobs', on_message_callback=lambda ch, method, prop, body: ch.basic_ack(delivery_tag=method.delivery_tag))
C. channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=True) channel.start_consuming()
D. def callback(ch, method, properties, body): process(body) channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=False) channel.start_consuming()

Solution

  1. Step 1: Understand message acknowledgment

    To acknowledge after processing, auto_ack must be False and manual ack called after process.
  2. Step 2: Analyze options

    def callback(ch, method, properties, body): process(body) ch.basic_ack(delivery_tag=method.delivery_tag) channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=False) channel.start_consuming() defines a callback that processes the message then calls basic_ack, with auto_ack=False and starts consuming.
  3. Final Answer:

    def callback(ch, method, properties, body): process(body) ch.basic_ack(delivery_tag=method.delivery_tag) channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=False) channel.start_consuming() -> Option A
  4. Quick Check:

    Manual ack after process with auto_ack=False [OK]
Hint: Use auto_ack=False and call basic_ack after processing [OK]
Common Mistakes:
  • Setting auto_ack=True disables manual ack
  • Not calling basic_ack causes message re-delivery
  • Calling basic_ack before processing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard