0
0
RabbitMQdevops~10 mins

Fair dispatch with prefetch in RabbitMQ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the prefetch count to 1 for fair dispatch.

RabbitMQ
channel.basic_qos(prefetch_count=[1])
Drag options to blanks, or click blank then click option'
A1
B0
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prefetch_count to 0 disables prefetch and can cause unfair dispatch.
Using a high prefetch_count can overload a single worker.
2fill in blank
medium

Complete the code to acknowledge a message manually after processing.

RabbitMQ
channel.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
Bmessage
Cchannel
Dprefetch_count
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to acknowledge using the message body instead of delivery tag.
Using channel or prefetch_count as delivery tag.
3fill in blank
hard

Fix the error in the consumer callback to enable fair dispatch with manual acknowledgments.

RabbitMQ
def callback(ch, method, properties, body):
    print(f"Received {body}")
    # Process message
    ch.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Abody
Bproperties
Cmethod.delivery_tag
Dch
Attempts:
3 left
💡 Hint
Common Mistakes
Using the message body or channel object as delivery tag.
Not acknowledging messages causing them to be requeued.
4fill in blank
hard

Fill both blanks to set up a channel with fair dispatch and manual acknowledgments.

RabbitMQ
channel.basic_qos(prefetch_count=[1])
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[2])
Drag options to blanks, or click blank then click option'
A1
BTrue
CFalse
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting auto_ack to True disables manual acknowledgment.
Using a prefetch count higher than 1 reduces fairness.
5fill in blank
hard

Fill all three blanks to complete the consumer setup for fair dispatch with manual ack and a callback function.

RabbitMQ
def callback(ch, method, properties, body):
    print(f"Received {body}")
    # Process message
    ch.basic_ack(delivery_tag=[1])

channel.basic_qos(prefetch_count=[2])
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[3])
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
B1
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using auto_ack=True disables manual ack.
Not setting prefetch count to 1 reduces fairness.