3. Given this consumer code snippet, what happens if the consumer crashes before ack?
channel.basic_consume(queue='task_queue', on_message_callback=callback)
def callback(ch, method, properties, body):
process_message(body)
# no ack sent here
medium
A. Message is lost and not requeued
B. Message remains unacknowledged and will be redelivered
C. Message is acknowledged automatically
D. Queue deletes the message immediately
Solution
Step 1: Understand manual ack behavior
If no ack is sent, RabbitMQ keeps message unacknowledged.
Step 2: Effect of consumer crash before ack
RabbitMQ will redeliver unacknowledged messages to another consumer.
Final Answer:
Message remains unacknowledged and will be redelivered -> Option B
Quick Check:
No ack = redelivery on crash [OK]
Hint: No ack means message redelivery on failure [OK]
Common Mistakes:
Assuming message is lost without ack
Thinking messages auto-acknowledge by default
Believing queue deletes messages immediately
4. You notice duplicate message processing in your RabbitMQ consumer. Which fix helps ensure exactly-once processing?
medium
A. Implement idempotent message handling and manual acks
B. Disable publisher confirms
C. Use automatic acknowledgments
D. Increase queue prefetch count
Solution
Step 1: Identify cause of duplicates
Duplicates often occur if messages are reprocessed after failure or redelivery.
Step 2: Apply exactly-once strategies
Idempotent handling plus manual acknowledgments prevent duplicate side effects.
Final Answer:
Implement idempotent message handling and manual acks -> Option A