RabbitTemplate receives and requests

I would like to receive messages from the queue so I can delete them immediately, in fact I would like to emulate the behavior of the rabbitMQ admin console, which can receive a message and request it.

So my question is, how do I do this? At first I tried to clone the message and re-send it, but it looks like the rabbitTemplate cannot send messages directly to the queue, and sending them to the exchange is not an option because it is possible that multiple queues will receive the message again.

Then I started thinking that I could receive the message and then somehow NACK it so that it would be in the queue again. The only question is how do I do it?

+3


source to share


1 answer


I think you can achieve this with basicReject

:



public class MyListener implements ChannelAwareMessageListener {

   public void onMessage(Message message, Channel channel) throws Exception {
        //Do something with message
        channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
   }

}

      

+2


source







All Articles