0
0
RabbitMQdevops~10 mins

Consumer acknowledgment strategies 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 acknowledge a message manually in RabbitMQ consumer.

RabbitMQ
channel.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Amessage
Bchannel
Cmethod.delivery_tag
Dqueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'channel' or 'queue' instead of the delivery tag.
Trying to acknowledge without specifying the delivery tag.
2fill in blank
medium

Complete the code to enable automatic acknowledgment in RabbitMQ consumer.

RabbitMQ
channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=[1])
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting auto_ack to False when automatic ack is desired.
Using None or 0 which are invalid for this parameter.
3fill in blank
hard

Fix the error in the manual acknowledgment code by completing the blank.

RabbitMQ
def callback(ch, method, properties, body):
    print(f"Received {body}")
    ch.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Ach.delivery_tag
Bproperties.delivery_tag
Cbody.delivery_tag
Dmethod.delivery_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using properties or body to get delivery_tag.
Trying to access delivery_tag from the channel object.
4fill in blank
hard

Fill both blanks to reject a message and requeue it in RabbitMQ consumer.

RabbitMQ
channel.basic_reject(delivery_tag=[1], requeue=[2])
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
BTrue
CFalse
Dchannel
Attempts:
3 left
💡 Hint
Common Mistakes
Using channel instead of delivery_tag.
Setting requeue to False which discards the message.
5fill in blank
hard

Fill all three blanks to consume messages with manual ack and reject unprocessable messages without requeue.

RabbitMQ
def callback(ch, method, properties, body):
    try:
        process(body)
        ch.basic_ack(delivery_tag=[1])
    except Exception:
        ch.basic_reject(delivery_tag=[2], requeue=[3])

channel.basic_consume(queue='jobs', on_message_callback=callback, auto_ack=False)
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
BTrue
CFalse
Dproperties.delivery_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using properties.delivery_tag instead of method.delivery_tag.
Setting requeue to True which requeues the message.