Consumer Acknowledgments
A mechanism that tells the broker that a message was successfully processed. Until the broker receives an ack, it holds the message and will redeliver it if the consumer disconnects.
Consumer acknowledgments should be used in any scenario where message delivery must be guaranteed. Without acknowledgments, the broker removes messages from the queue immediately after transmission, risking data loss if the consumer fails during processing. Use acknowledgments to ensure "at-least-once" delivery, unless the application prioritizes maximum throughput over strict data integrity.
Manual acknowledgements
Manual acknowledgements are the default. Ack after successful processing, nack to requeue on failure:
def on_message(channel, method, properties, body):
try:
process(body)
channel.basic_ack(delivery_tag=method.delivery_tag)
except Exception:
# Requeue the message for another consumer to retry
channel.basic_nack(delivery_tag=method.delivery_tag, requeue=True)
channel.basic_consume(queue="tasks", on_message_callback=on_message)
channel.start_consuming()Automatic acknowledgements
The broker considers the message delivered as soon as it leaves. If the consumer crashes before processing, the message is lost. Only use this when occasional loss is acceptable.
channel.basic_consume('hello', callback, auto_ack=True)Acknowledgement types
basic.ack— message processed, discard from queue.basic.nack— negative ack, supports bulk messages (LavinMQ extension).basic.reject— same as nack but single messages only (AMQP standard).
To requeue a message:
channel.basicReject(deliveryTag, true)Acknowledging multiple messages
Set multiple=True to ack all unacknowledged messages on the channel up to and including the given delivery tag:
channel.basicNack(deliveryTag, true, true)Preventing redelivery loops
If a message is repeatedly requeued without being processed, LavinMQ’s x-delivery-limit policy breaks the loop. Messages that exceed the limit are dropped or routed to a dead letter exchange. The current count is available via the x-delivery-count header.
Prefetch
Prefetch controls how many unacknowledged messages LavinMQ delivers to a consumer at once. Without it, a consumer receives an unbounded number of messages on connect, regardless of its processing capacity.
channel.basic_qos(prefetch_count=10)LavinMQ won’t deliver more messages until some are acknowledged. It also distributes load more evenly when multiple consumers share a queue.
Ready to take the next steps?
Managed LavinMQ instance via CloudAMQP
LavinMQ has been built with performance and ease of use in mind - we've benchmarked a throughput of about 1,000,000 messages/sec . You can try LavinMQ without any installation hassle by creating a free instance on CloudAMQP. Signing up is a breeze.
Get started with CloudAMQP ->Help and feedback
We welcome your feedback and are eager to address any questions you may have about this piece or using LavinMQ. Join our Slack channel to connect with us directly. You can also find LavinMQ on GitHub.