0
0
RabbitMQdevops~10 mins

Handling consumer failures 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 after processing it successfully.

RabbitMQ
channel.basic_ack(delivery_tag=[1])
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
Bchannel.delivery_tag
Cmessage.delivery_tag
Dconsumer_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong object to get delivery tag
Trying to acknowledge with consumer tag
2fill in blank
medium

Complete the code to reject a message and requeue it for later processing.

RabbitMQ
channel.basic_reject(delivery_tag=[1], requeue=[2])
Drag options to blanks, or click blank then click option'
AFalse
BTrue
Cmethod.delivery_tag
Dchannel.delivery_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong delivery tag
Setting requeue to false by mistake
3fill in blank
hard

Fix the error in the code to properly handle a failed message by rejecting without requeue.

RabbitMQ
channel.basic_reject(delivery_tag=[1], requeue=[2])
Drag options to blanks, or click blank then click option'
Amethod.delivery_tag
BFalse
CTrue
Dchannel.delivery_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong delivery tag
Setting requeue to true when discarding
4fill in blank
hard

Fill both blanks to create a dead-letter exchange binding for failed messages.

RabbitMQ
channel.queue_declare(queue='failed', arguments=[1])
channel.queue_bind(queue='failed', exchange=[2], routing_key='failed')
Drag options to blanks, or click blank then click option'
A{'x-dead-letter-exchange': 'dlx'}
B'failed'
C'dlx'
D'main-exchange'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exchange name
Not setting dead-letter exchange in arguments
5fill in blank
hard

Fill all three blanks to implement a consumer callback that retries a message once before rejecting it.

RabbitMQ
def callback(ch, method, properties, body):
    retries = int(properties.headers.get('[1]', 0)) if properties.headers else 0
    if retries < [2]:
        headers = properties.headers or {}
        headers['[3]'] = retries + 1
        properties.headers = headers
        ch.basic_publish(exchange='', routing_key=method.routing_key, body=body, properties=properties)
        ch.basic_ack(delivery_tag=method.delivery_tag)
    else:
        ch.basic_reject(delivery_tag=method.delivery_tag, requeue=False)
Drag options to blanks, or click blank then click option'
Ax-retries
B1
Cretry-count
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent header keys
Incorrect retry count comparison