我的消费者听队列 . Auto Ack = false . - 如果我确认消息将从队列中删除 . - 如果我没有确认,RabbitMQ会按预期将消息放入队列 . 我的问题是我的消费者没有继续听这些未经确认的消息 . 为了验证,如果我发出新消息,消费者就会把它拿起来 .
以下是我的代码块 . 有解决方案吗
while (true) {
try {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
String response = sendEndpoint(message);
if (!response.equals(ERROR_CODE)) {
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
} catch (InterruptedException ignore) {
continue;
}
}
1 回答
你尝试过basic.reject吗?如in this blog entry所述,basic.reject将它传递到同一队列和"RabbitMQ doesn't take care to stop the same consumer getting the message again" . 所以这对你有用 .
根据您的目的,您也可能对死信功能感兴趣 . 有关更多信息,请参见here .