RabbitTemplate receive and requeue

元气小坏坏 提交于 2019-12-10 21:37:24

问题


I would like to receive messages from a queue an immediately dequeue them, in fact I would like to mimic the behaviour of the rabbitMQ admin console which can receive a message and requeue it.

So my question is how to do this? At first I was trying to make a clone of the message and re-send them, but it seems that the rabbitTemplate is not able to send messages directly to a queue and sending them to an exchange is not an option because it could be possible that multiple queues will receive the message again.

Then I started thinking that I could receive a message and then somehow NACK it so that it ends up back on the queue. The only question there is how should I do that?


回答1:


I think you can achieve that 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);
   }

}


来源:https://stackoverflow.com/questions/25876178/rabbittemplate-receive-and-requeue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!