Complete the code to acknowledge a message after processing in RabbitMQ consumer.
channel.basic_ack(delivery_tag=[1])channel.delivery_tag which does not exist.delivery_tag without context.In RabbitMQ, the delivery tag is accessed via method.delivery_tag to acknowledge a message.
Complete the code to declare a durable queue in RabbitMQ.
channel.queue_declare(queue='task_queue', durable=[1])
Setting durable=True ensures the queue survives RabbitMQ restarts.
Fix the error in the consumer callback to ensure idempotent processing by checking message ID.
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)
message_id_header or message_id_property.The message ID is accessed via properties.message_id to track processed messages for idempotency.
Fill both blanks to create a dictionary comprehension that stores message IDs and their bodies only if the ID is not already processed.
new_messages = {msg.[1]: msg.[2] for msg in messages if msg.[1] not in processed_ids}timestamp or delivery_tag instead of message_id or body.We use message_id as the key and body as the value to store unprocessed messages.
Fill all three blanks to complete the RabbitMQ consumer setup with manual acknowledgments and prefetch count for idempotent processing.
channel.basic_qos(prefetch_count=[1]) channel.basic_consume(queue='task_queue', on_message_callback=[2], auto_ack=[3]) channel.start_consuming()
auto_ack=True which disables manual ack.Setting prefetch_count=1 limits unacknowledged messages to one. The callback function handles messages. auto_ack=False enables manual acknowledgments for idempotency.