0
0
RabbitMQdevops~10 mins

Idempotent consumers 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 in RabbitMQ consumer.

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
Ddelivery_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using channel.delivery_tag which does not exist.
Using delivery_tag without context.
2fill in blank
medium

Complete the code to declare a durable queue in RabbitMQ.

RabbitMQ
channel.queue_declare(queue='task_queue', durable=[1])
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting durable to False which makes the queue temporary.
Using None or 0 which are invalid for durable parameter.
3fill in blank
hard

Fix the error in the consumer callback to ensure idempotent processing by checking message ID.

RabbitMQ
def callback(ch, method, properties, body):
    message_id = properties.[1]
    if message_id in processed_ids:
        ch.basic_ack(delivery_tag=method.delivery_tag)
        return
    # process message
    processed_ids.add(message_id)
    ch.basic_ack(delivery_tag=method.delivery_tag)
Drag options to blanks, or click blank then click option'
Amessage_id_property
Bmessage_id_header
Cmessage_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like message_id_header or message_id_property.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores message IDs and their bodies only if the ID is not already processed.

RabbitMQ
new_messages = {msg.[1]: msg.[2] for msg in messages if msg.[1] not in processed_ids}
Drag options to blanks, or click blank then click option'
Amessage_id
Bbody
Ctimestamp
Ddelivery_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using timestamp or delivery_tag instead of message_id or body.
5fill in blank
hard

Fill all three blanks to complete the RabbitMQ consumer setup with manual acknowledgments and prefetch count for idempotent processing.

RabbitMQ
channel.basic_qos(prefetch_count=[1])
channel.basic_consume(queue='task_queue', on_message_callback=[2], auto_ack=[3])
channel.start_consuming()
Drag options to blanks, or click blank then click option'
A1
Bcallback
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting auto_ack=True which disables manual ack.
Using wrong callback function name.
Setting prefetch_count to 0 or more than 1.