无法按优先级顺序获取消息

无法按优先级顺序获取消息

本文介绍了无法按优先级顺序获取消息 Spring camel rabbitmq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是spring camel rabbitmq的初学者.

我可以通过在生产者端的交换头中设置消息头中的消息优先级,如下所示:

I am able to set message priority in message header by setting it in exchange out headers on the producer side, like this :

exchange.getOut().setHeader("rabbitmq.PRIORITY", 1);

但是在使用消息时,它们并没有按优先级顺序排列.帮助!!

BUT while consuming the messages they dont come in there order of priority. HELP !!

我可以在 rabbitmq 的 Web 界面中看到,优先级标头已适当设置

I can see in web interface of rabbitmq that priority header in appropriately set

推荐答案

解决了这个问题.问题是我无法使用 camel 端点设置 x-max-priority.需要在队列中的queueArgsConfigurer 选项中添加它.为此,我们需要像这样实现 ArgsConfigurer 接口:

got the issue.problem was that I was not able to set x-max-priority using camel endpoints.Need to add it in queueArgsConfigurer option in queue.To do this we need to implement ArgsConfigurer interface like this :

@Component(value="QueueArgsConfigurer")
public class QueueArgsConfigurer implements ArgsConfigurer {
@Override
public void configurArgs(Map<String, Object> map) {
    map.put("x-max-priority", 3);
}

}

并添加到队列端点 queueArgsConfigurer 选项,如下所示:queueArgsConfigurer=#QueueArgsConfigurer由于我使用的是 spring,我通过它的 bean 名称获得了 QueueArgsConfigurer.

And add to queue endpoint queueArgsConfigurer option like this: queueArgsConfigurer=#QueueArgsConfigurerSince I am using spring I get the QueueArgsConfigurer by its bean name.

这篇关于无法按优先级顺序获取消息 Spring camel rabbitmq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:37