Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what is the difference between reject and ack #84

Closed
geyang opened this issue Jul 23, 2015 · 4 comments
Closed

what is the difference between reject and ack #84

geyang opened this issue Jul 23, 2015 · 4 comments
Labels

Comments

@geyang
Copy link

geyang commented Jul 23, 2015

Hi, Here is a dumb question:

What is the difference between reject and ack?

Thanks!
Ge

@mxriverlynn
Copy link
Contributor

Hi @episodeyang,

ack will acknowledge the message, which tells RabbitMQ that this message has been handled. RabbitMQ will mark the message as acknowledged, and remove it from the queue permanently. (see https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.ack)

nack is a "negative acknowledge" or "not acknowledged" - this tells RabbitMQ that the message was not handled properly. By default, 'nack' will put the message back in the queue for later handling. You can also force the message to not requeue with 'nack'. (see https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.nack)

'reject' is an explicit "not acknowledged" and do not requeue (by default). RabbitMQ will drop the message from the queue entirely, as the message will not be processable in that queue. you can specify a 'requeue' parameter for reject, like nack. (see https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.reject)

The advantage of 'nack' over reject is that nack works with mutliple messages if you want it to. reject, i think, is for a single message.

personally, i use nack to put a message back on the queue and handle it later and reject to say i can't do anything with the message at all. but that's just how i use them.

i'm a little fuzzy on the exact details, still... but i think in general these descriptions are pretty close

@geyang
Copy link
Author

geyang commented Oct 20, 2015

Thanks for the explanation!

@kcarmonamurphy
Copy link

kcarmonamurphy commented Jan 30, 2018

very well explained. thanks @derickbailey !

@linxiaobai
Copy link

linxiaobai commented Oct 22, 2018

 /**
     * Acknowledge one or several received
     * messages. Supply the deliveryTag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}
     * or {@link com.rabbitmq.client.AMQP.Basic.Deliver} method
     * containing the received message being acknowledged.
     * @see com.rabbitmq.client.AMQP.Basic.Ack
     * @param deliveryTag the tag from the received {@link com.rabbitmq.client.AMQP.Basic.GetOk} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}
     * @param multiple true to acknowledge all messages up to and
     * including the supplied delivery tag; false to acknowledge just
     * the supplied delivery tag.
     * @throws java.io.IOException if an error is encountered
     */
    void basicAck(long deliveryTag, boolean multiple) throws IOException;

    /**
     * Reject one or several received messages.
     *
     * Supply the <code>deliveryTag</code> from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}
     * or {@link com.rabbitmq.client.AMQP.Basic.GetOk} method containing the message to be rejected.
     * @see com.rabbitmq.client.AMQP.Basic.Nack
     * @param deliveryTag the tag from the received {@link com.rabbitmq.client.AMQP.Basic.GetOk} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}
     * @param multiple true to reject all messages up to and including
     * the supplied delivery tag; false to reject just the supplied
     * delivery tag.
     * @param requeue true if the rejected message(s) should be requeued rather
     * than discarded/dead-lettered
     * @throws java.io.IOException if an error is encountered
     */
    void basicNack(long deliveryTag, boolean multiple, boolean requeue)
            throws IOException;

    /**
     * Reject a message. Supply the deliveryTag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}
     * or {@link com.rabbitmq.client.AMQP.Basic.Deliver} method
     * containing the received message being rejected.
     * @see com.rabbitmq.client.AMQP.Basic.Reject
     * @param deliveryTag the tag from the received {@link com.rabbitmq.client.AMQP.Basic.GetOk} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}
     * @param requeue true if the rejected message should be requeued rather than discarded/dead-lettered
     * @throws java.io.IOException if an error is encountered
     */
    void basicReject(long deliveryTag, boolean requeue) throws IOException;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants