gpt4 book ai didi

rabbitmq - Spring AMQP : Message Priority not working working

转载 作者:行者123 更新时间:2023-12-02 21:48:18 27 4
gpt4 key购买 nike

我正在使用 Sprin AMQP 的rabbittemplate 通过 RabbitMQ 发送和接收消息。我能够发送和接收消息,但是,我想优先处理消息。

例如,如果我推送 1000 条消息,假设奇数消息的优先级为 1,偶数消息的优先级为 0,然后我启动消费者,那么消费者应该首先接收奇数消息,然后接收偶数消息号码消息。

这是我的代码:制作人:

public void sendMessage(int i) throws IOException {
Record r = new Record();
r.setFrom((i + 1));
r.setTo("infoimage");
r.setMessage("Hi Pritish.");
MessageProperties prop = new MessageProperties();
prop.setPriority(i%2);
byte[] rByte = serialize(r);
Message m = new Message(rByte, prop);
rabbitTemplate.convertAndSend(queueName, m);
}

消费者:

public MessageListener exampleListener() {
return new MessageListener() {
public void onMessage(Message message) {
//do some job
}

}; }

我做错了什么吗?有人可以帮我解决这个问题吗?

最佳答案

3.5.0 版本之前,RabbitMQ doesn't support priority out of the box .

a plugin不过。

您还可以通过使用多个队列来模拟优先级,但只有当高优先级消息的数量(与低优先级消息相比)较少时,这才真正有效。

关于rabbitmq - Spring AMQP : Message Priority not working working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25089031/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com