Complete the code to set the prefetch count to 1 for fair dispatch.
channel.basic_qos(prefetch_count=[1])Setting prefetch_count to 1 tells RabbitMQ to send only one message at a time to a worker, enabling fair dispatch.
Complete the code to acknowledge a message manually after processing.
channel.basic_ack(delivery_tag=[1])The delivery_tag from the method frame is used to acknowledge the message manually.
Fix the error in the consumer callback to enable fair dispatch with manual acknowledgments.
def callback(ch, method, properties, body): print(f"Received {body}") # Process message ch.basic_ack(delivery_tag=[1])
Manual acknowledgment requires the delivery tag from the method parameter, which is method.delivery_tag.
Fill both blanks to set up a channel with fair dispatch and manual acknowledgments.
channel.basic_qos(prefetch_count=[1]) channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[2])
Setting prefetch_count to 1 enables fair dispatch. Setting auto_ack to False requires manual acknowledgment.
Fill all three blanks to complete the consumer setup for fair dispatch with manual ack and a callback function.
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])
The callback acknowledges messages using method.delivery_tag. Prefetch count is set to 1 for fair dispatch. auto_ack is False to require manual acknowledgment.