0

I put records from a file into rabbit mq,read records from queue and call a service.For rejected records,I am sending a negative acknowledgemnt and requeuing with channel.basicNack method.But requirement is that we need to make only some 3 attempts of service call.After that we have to remove the message from the queue rather keep on calling the service again and again.

user
  • 173
  • 2
  • 15

1 Answers1

1

On the last attempt, set the requeue argument in basicNack to false.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks for the response Gary.I want to know how to do the check of the number of times same message has been processed.I somewhere read about setting the header count properties.getHeaders().put("x-header-count", count++) where properties is of type AMQP.BasicProperties as an argument to the handleDelivery() of consumer – user Sep 22 '16 at 07:10
  • No; that won't help - RabbitMQ redelivers the same message - you won't see any changed headers. The only thing it provides is a boolean `redelivered` property. You have to maintain state (number of attempts) in your application, based on something unique in the message. Spring AMQP's stateful retry interceptor uses the messageId header by default, but that requires the sender to set it to a unique value. – Gary Russell Sep 22 '16 at 12:45
  • Thanks.But channel.basicNack(envelope.getDeliveryTag(), false, true); is not requeuing the message.While publishing I am setting messageID to some unique value.Now while consuming ,I check if this messageID has been redelivered.So is it that the messageID of properties does not retain after redelivery of the same message ?If not,then can u please suggest some way ? – user Sep 27 '16 at 04:51
  • It worked.It was my mistake.I had specified ack to true in basicConsume().Thanks – user Sep 27 '16 at 10:30