【发布时间】:2016-12-13 22:18:11
【问题描述】:
在重新排队消息时,我们希望将消息放置在队列的开头/前面。 这意味着如果我在队列中作为“D、C、B、A”和进程 A,然后想在开始时放回队列中,我的队列应该如下所示:- “A,D,C,B”。 因此,我应该能够处理 B,并且由于 A 在队列的开头移动,因此应该在末尾处理它。
有趣的是,当尝试使用 rabbitMQ 的本机 AMQP 库时,它可以按上述预期工作。
但是,当我们通过 spring AMQP library 进行处理时,消息仍然保留在原来的位置,不会到达队列的最前面。
这是我们尝试过的代码:
public void onMessage(Message message, com.rabbitmq.client.Channel channel) throws Exception {
if(new String(message.getBody()).equalsIgnoreCase("A")){
System.out.println("Message = =="+new String(message.getBody()));
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
}else{
System.out.println("Message ==="+new String(message.getBody()));
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
}
}
知道为什么它在 Spring 中不起作用但在 rabbimq amqp 本机库中起作用吗?
Spring AMQP 版本:spring-amqp-1.4.5.RELEASE Rabbitmq amqp 客户端版本:3.5.1
【问题讨论】:
标签: rabbitmq spring-amqp spring-rabbit