RabbitMQ basic.get and acknowledgement

前端 未结 2 712
情深已故
情深已故 2021-01-17 01:25

I\'m invoking:

GetResponse response = channel.basicGet(\"some.queue\", false); // no auto-ack
....
channel.basicAck(deliveryTag, ...);

Howe

2条回答
  •  别那么骄傲
    2021-01-17 01:51

    I'm doing the following to mimic Delaying the ack:

    At consumption time

    1. Get(consume) the message form the initial Queue.
    2. Create a "PendingAck_123456" Queue.
      123456 is a unique id of the message.
      Set the following properties
      • x-message-ttl (to requeue after timeout)
      • x-expires (to make sure the temp queue will be deleted)
      • x-dead-letter-exchange and x-deal-letter-routing-key to requeue to the initial Queue upon TTL expiration.
    3. Publish the message Pending ack to this "PendingAck_123456" Queue
    4. Ack the message to delete it from the initial queue

    At Acknowledge time

    1. Calculate Queue Name from Message Id and Get from the "PendingAck_123456" Queue
    2. Acknowledge it (no need to call .getBody() ).
      That'll delete it from this pending queue, preventing the TTL to requeue it

    Remarks

    • A Queue for only 1 message.. Is that an issue if there are a lot of such Queues ?
    • A requeued message will be sent at the queue input side.. not at the queue output (as would do a real ack).. There is an impact on the messages order.
    • Message is copied by the application to the Pending Queue.. This is an additional step that may have impacts on the overall performance.
    • To mimic a Nack/Reject, you you may want to Copy the message to the Initial Queue, and Ack it from the PendingAck queue. By default, the TTL would do it (later).

提交回复
热议问题