据我在 上看到的rabbitmq 文档中,排队的消息以循环方式分发给连接的消费者。但是,我希望我的一位消费者仅接收 1% 的消息用于试点测试。
有可能实现吗?任何想法都会有所帮助。
谢谢
最佳答案
我认为您正在寻找 consumer priorities .
RabbitMQ 将比低优先级消费者更频繁地向高优先级消费者发送消息。只有在高优先级消费者被阻塞时才会到达低优先级消费者。当消费者达到未确认消息的最大数量时,它就会被阻塞。这可以通过玩 basic.qos
来设置。对于消费者。
消费者的优先级可以通过以下方式设置:
Set the
x-priority
argument in thebasic.consume
method to an integer value. Consumers which do not specify a value have priority 0. Larger numbers indicate higher priority, and both positive and negative numbers can be used.
因此,您可以为您的测试使用者和其他使用者定义优先级。
这是 RabbitMQ 文档提供的示例。
Channel channel = ...;
Consumer consumer = ...;
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-priority", 10);
channel.basicConsume("my-queue", false, args, consumer);
如果您严格想要控制跨客户端的消息分发,您可能需要编写一个自定义插件来修改 consumers 的行为。 .
关于java - 改变 RabbitMQ 消费者权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61496541/