【问题标题】:How to browse the queue in rabbitmq without dequeuing the messages如何在不使消息出队的情况下浏览rabbitmq中的队列
【发布时间】:2016-05-21 06:51:33
【问题描述】:

我正在尝试获取具有特定相关 id 的消息,如 rabbitmq 文档中所述。但是我看到不相关的消息出队了。我不希望它发生。在我收到消息并知道这不是我要找的那个之后,我如何告诉 rabbitmq 不要出队。请帮帮我。

`

.
.
replyQueueName = channel.queueDeclare().getQueue();
consumer = new QueueingConsumer(channel);
channel.basicConsume(replyQueueName, false, consumer);
while (true) {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            System.out.println(delivery.getProperties().getCorrelationId());
            if (delivery.getProperties().getCorrelationId().equals(corrId)) {
                response = new String(delivery.getBody());
                break;
            }
        }

`

【问题讨论】:

    标签: java rabbitmq message-queue


    【解决方案1】:

    你不能按照你想要的方式做你想做的事。 “选择性消费者”是 RabbitMQ 中的一种反模式。

    相反,您应该设计您的 RabbitMQ 设置,以便将您的消息路由到仅包含目标消费者的消息的队列。

    我在这里写了更多关于此的内容:http://derickbailey.com/2015/07/22/airport-baggage-claims-selective-consumers-and-rabbitmq-anti-patterns/

    【讨论】:

    • Azure Service Bus 和 WSO2 具有队列浏览功能。我很惊讶 RabbitMQ 没有它。
    【解决方案2】:

    如果您可以承受丢失消息顺序的后果,您可以使用重新排队机制。

    尝试关闭自动确认。

    如果没有,您必须重新设计应用程序以注入标头或路由键以路由到特定队列。

    【讨论】:

      猜你喜欢
      • 2013-08-09
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 2019-12-08
      • 1970-01-01
      • 2011-06-30
      相关资源
      最近更新 更多