I'm using rabbitMQ, I take every message from queue with basic_get without automatically acking procedure, which means the message remain in queue until I ack or nack the message.
Sometimes I've messages that can't be processed because of some exception thrown, which prevented them from being fully processed.
Question is what does it matter if I both ack the messages in success and exception thrown, I mean in terms of result messages will always get out of the queue, so what does it matter if I use ack or nack in this scenario? Maybe I miss something about when using each opration?
To reject messages in bulk, clients set the multiple flag of the basic. nack method to true. The broker will then reject all unacknowledged, delivered messages up to and including the message specified in the delivery_tag field of the basic.
A consumer tag is a consumer identifier which can be either client- or server-generated. To let RabbitMQ generate a node-wide unique tag, use a Channel#basicConsume override that doesn't take a consumer tag argument or pass an empty string for consumer tag and use the value returned by Channel#basicConsume.
RabbitMQ uses a push-based model with a smart producer, which means the producer decides when to push data. A prefetch limit is defined on the consumer to stop the producer from overwhelming consumers. Such a push-based approach is suited for low latency messaging.
The basic.nack command is apparently a RabbitMQ extension, which extends the functionality of basic.reject to include a bulk processing mode. Both include a "bit" (i.e. boolean) flag of requeue
, so you actually have several choices:
nack
/reject
with requeue=1
: the message will be returned to the queue it came from as though it were a new message; this might be useful in case of a temporary failure on the consumer sidenack
/reject
with requeue=0
and a configured Dead Letter Exchange (DLX), will publish the message to that exchange, allowing it to be picked up by another queuenack
/reject
with requeue=0
and no DLX will simply discard the messageack
will remove the message from the queue even if a DLX is configuredIf you have no DLX configured, always using ack
will be the same as nack
/reject
with requeue=0
; however, using the logically correct function from the start will give you more flexibility to configure things differently later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With