Bird
Raised Fist0
RabbitMQdevops~20 mins

Work queue for task distribution in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
RabbitMQ Work Queue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
RabbitMQ Work Queue: Message Acknowledgment Behavior
Consider a RabbitMQ work queue where a worker receives a message but crashes before sending an acknowledgment. What happens to the message in the queue?
AThe message remains unacknowledged and is requeued for another worker.
BThe message is lost and removed from the queue.
CThe message is acknowledged automatically by RabbitMQ.
DThe message is duplicated and sent to all workers.
Attempts:
2 left
💡 Hint
Think about how RabbitMQ ensures tasks are not lost if a worker fails.
❓ Configuration
intermediate
2:00remaining
Configuring RabbitMQ Prefetch Count for Fair Dispatch
Which configuration setting ensures that a RabbitMQ worker receives only one unacknowledged message at a time to balance load fairly?
ASet auto_ack to true when consuming messages
BSet prefetch_count to 0 to allow unlimited messages
CSet durable flag to true on the queue
DSet prefetch_count to 1 using channel.basic_qos(prefetch_count=1)
Attempts:
2 left
💡 Hint
This setting limits how many messages a worker can hold without acknowledging.
🔀 Workflow
advanced
2:30remaining
RabbitMQ Work Queue: Task Distribution Workflow
Arrange the steps in the correct order for a RabbitMQ work queue where tasks are distributed fairly and reliably to workers.
A1,3,2,4
B1,2,3,4
C2,1,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint
Think about queue setup, message publishing, worker configuration, then processing.
❓ Troubleshoot
advanced
2:00remaining
Troubleshooting RabbitMQ Work Queue: Messages Not Being Redelivered
A worker crashes while processing a message but the message is not redelivered to other workers. What is the most likely cause?
AThe queue is not durable, so messages are lost on worker crash.
BThe prefetch_count is set to 1, limiting message delivery.
CThe worker is using auto_ack=True, so messages are acknowledged immediately.
DThe message was published as non-persistent.
Attempts:
2 left
💡 Hint
Check how message acknowledgments are handled by the worker.
✅ Best Practice
expert
3:00remaining
Best Practice for Ensuring Reliable Task Processing in RabbitMQ Work Queues
Which practice best ensures that tasks are not lost and are fairly distributed among workers in a RabbitMQ work queue?
ADeclare durable queues, publish persistent messages, use manual acknowledgments, and set prefetch_count=1.
BUse non-durable queues with auto_ack=True for faster processing.
CPublish messages without persistence and rely on worker retries.
DSet prefetch_count to 0 and use auto_ack=False for unlimited message delivery.
Attempts:
2 left
💡 Hint
Think about durability, acknowledgments, and fair load distribution.

Practice

(1/5)
1. What is the main purpose of a work queue in RabbitMQ?
easy
A. To create a backup of messages
B. To distribute tasks among multiple workers safely
C. To store user login information
D. To encrypt messages for security

Solution

  1. Step 1: Understand the role of work queues

    Work queues are designed to share tasks among many workers so that the workload is balanced and tasks are processed efficiently.
  2. Step 2: Eliminate unrelated options

    Storing login info, backing up messages, or encrypting messages are not the primary functions of work queues.
  3. Final Answer:

    To distribute tasks among multiple workers safely -> Option B
  4. Quick Check:

    Work queue = task distribution [OK]
Hint: Work queues share tasks among workers, not store or encrypt data [OK]
Common Mistakes:
  • Confusing work queues with message encryption
  • Thinking work queues store user data
  • Assuming work queues backup messages automatically
2. Which RabbitMQ queue declaration option makes the queue survive server restarts?
easy
A. durable: true
B. autoDelete: true
C. exclusive: true
D. passive: true

Solution

  1. Step 1: Identify durability option

    The 'durable: true' option ensures the queue is saved to disk and survives RabbitMQ server restarts.
  2. Step 2: Understand other options

    'autoDelete' removes the queue when no consumers remain, 'exclusive' restricts queue to one connection, and 'passive' checks for queue existence without creating it.
  3. Final Answer:

    durable: true -> Option A
  4. Quick Check:

    durable = survive restart [OK]
Hint: Durable queues survive restarts; autoDelete removes queues [OK]
Common Mistakes:
  • Using autoDelete instead of durable for persistence
  • Confusing exclusive with durability
  • Thinking passive creates durable queues
3. Given this worker code snippet in Python using pika:
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=False)
channel.start_consuming()
What happens if the worker crashes before sending an acknowledgment?
medium
A. The message is requeued and delivered to another worker
B. The queue deletes all messages
C. The message is acknowledged automatically
D. The message is lost and never processed again

Solution

  1. Step 1: Understand auto_ack=False behavior

    With auto_ack set to False, the worker must explicitly acknowledge messages after processing.
  2. Step 2: Effect of worker crash before ack

    If the worker crashes before ack, RabbitMQ requeues the message to deliver it to another worker, ensuring no task is lost.
  3. Final Answer:

    The message is requeued and delivered to another worker -> Option A
  4. Quick Check:

    auto_ack=False + crash = requeue message [OK]
Hint: auto_ack=False means unacked messages get requeued on crash [OK]
Common Mistakes:
  • Assuming messages are lost without ack
  • Thinking messages auto-acknowledge on delivery
  • Believing queue deletes messages on worker failure
4. You wrote this code to declare a durable queue:
channel.queue_declare(queue='task_queue', durable=False)
Why might this cause task loss after RabbitMQ restarts?
medium
A. Because exclusive=True is missing
B. Because the queue name is invalid
C. Because durable=True deletes messages on restart
D. Because durable=False means the queue is deleted on restart

Solution

  1. Step 1: Analyze durable flag effect

    Setting durable=False means the queue is temporary and will be deleted when RabbitMQ restarts.
  2. Step 2: Consequence on task persistence

    Since the queue is deleted, any unprocessed tasks in it are lost after restart.
  3. Final Answer:

    Because durable=False means the queue is deleted on restart -> Option D
  4. Quick Check:

    durable=False = queue lost on restart [OK]
Hint: durable=False queues vanish on restart, losing tasks [OK]
Common Mistakes:
  • Confusing durable with exclusive
  • Thinking queue name causes loss
  • Believing durable=True deletes messages
5. You want to ensure tasks are not lost even if RabbitMQ crashes and workers fail. Which combination of settings should you use for the queue and messages?
hard
A. Declare queue with autoDelete=true and publish messages with delivery_mode=1
B. Declare queue with exclusive=true and publish messages with delivery_mode=1
C. Declare queue with durable=true and publish messages with delivery_mode=2
D. Declare queue with durable=false and publish messages with delivery_mode=2

Solution

  1. Step 1: Ensure queue durability

    Setting durable=true makes the queue survive RabbitMQ restarts, preventing loss of the queue itself.
  2. Step 2: Make messages persistent

    Publishing messages with delivery_mode=2 marks them as persistent, so they are saved to disk and not lost on server crash.
  3. Step 3: Understand why other options fail

    autoDelete=true deletes the queue when no consumers remain, exclusive=true restricts queue to one connection, and durable=false means queue is temporary. delivery_mode=1 means messages are transient and can be lost.
  4. Final Answer:

    Declare queue with durable=true and publish messages with delivery_mode=2 -> Option C
  5. Quick Check:

    durable queue + persistent messages = no loss [OK]
Hint: Durable queue + delivery_mode=2 messages prevent loss [OK]
Common Mistakes:
  • Using autoDelete instead of durable for persistence
  • Publishing messages without delivery_mode=2
  • Confusing exclusive with durability
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