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.
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.
LavinMQ supports manual and automatic acknowledgements. Manual acknowledgements give full control over when a message is confirmed, while automatic acknowledgements let the broker consider a message delivered as soon as it is sent.
Acknowledgement types
LavinMQ supports three acknowledgement types:
basic.ack— message processed successfully, broker removes it from the queue.basic.nack— processing failed, rejects one or more messages (LavinMQ extension).basic.reject— same as nack but single messages only (AMQP standard).
To requeue a message:
channel.basic_reject(delivery_tag=method.delivery_tag, requeue=True)Manual Acknowledgements
Use basic_ack on success and basic_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 is sent to the consumer. 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)Acknowledging multiple messages
Set multiple=True to ack all unacknowledged messages on the channel up to and including the given delivery tag:
channel.basic_nack(delivery_tag=method.delivery_tag, multiple=True, requeue=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 if one is configured. The current count is available via the x-delivery-count header.
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.