0
0
RabbitMQdevops~20 mins

Fair dispatch with prefetch in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fair Dispatch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the purpose of prefetch in RabbitMQ

What is the main purpose of setting the prefetch count in RabbitMQ when using fair dispatch?

ATo ensure a consumer receives only one message at a time until it acknowledges it
BTo limit the number of messages sent over the network at once
CTo increase the message queue size on the broker
DTo automatically reject messages that take too long to process
Attempts:
2 left
💡 Hint

Think about how RabbitMQ controls message flow to consumers to balance workload.

💻 Command Output
intermediate
2:00remaining
Effect of prefetch count on message delivery

Given two consumers connected to the same RabbitMQ queue with prefetch=1, what will be the output behavior when 4 messages are published?

RabbitMQ
Consumer1: prefetch=1
Consumer2: prefetch=1
Publish 4 messages to queue
AConsumer1 receives all 4 messages before Consumer2 gets any
BBoth consumers receive 2 messages each simultaneously
CMessages are sent randomly without regard to prefetch settings
DMessages are distributed one by one alternately between Consumer1 and Consumer2
Attempts:
2 left
💡 Hint

Consider how prefetch=1 affects message dispatch to multiple consumers.

Configuration
advanced
2:00remaining
Configuring prefetch count in RabbitMQ consumer code

Which of the following code snippets correctly sets the prefetch count to 1 in a RabbitMQ consumer using Python's pika library?

A
channel.set_qos(prefetch=1)
channel.consume('task_queue', callback)
Bchannel.basic_consume(queue='task_queue', on_message_callback=callback, prefetch_count=1)
C
channel.basic_qos(prefetch_count=1)
channel.basic_consume(queue='task_queue', on_message_callback=callback)
D
channel.qos(prefetch=1)
channel.basic_consume('task_queue', callback)
Attempts:
2 left
💡 Hint

Look for the correct method name and parameter for setting prefetch in pika.

Troubleshoot
advanced
2:00remaining
Diagnosing message imbalance despite prefetch=1

You set prefetch=1 for two consumers on the same queue, but one consumer receives most messages while the other is idle. What is the most likely cause?

AThe idle consumer is not acknowledging messages, causing RabbitMQ to stop sending it new messages
BPrefetch count must be set to 0 to enable fair dispatch
CRabbitMQ does not support fair dispatch with multiple consumers
DThe queue is configured as exclusive, so only one consumer can receive messages
Attempts:
2 left
💡 Hint

Think about how unacknowledged messages affect message flow.

🔀 Workflow
expert
2:30remaining
Order of steps to implement fair dispatch with prefetch in RabbitMQ

Arrange the following steps in the correct order to implement fair dispatch with prefetch=1 in a RabbitMQ consumer application.

A1,3,2,4
B1,2,3,4
C3,1,2,4
D2,1,3,4
Attempts:
2 left
💡 Hint

Consider the logical order of setup before starting consumption.