如何使用Spring JmsTemplate为嵌入式activeMQ设置消息优先级? [英] How to set message priority for embedded activeMQ using spring JmsTemplate?

查看:418
本文介绍了如何使用Spring JmsTemplate为嵌入式activeMQ设置消息优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循本指南- https://spring.io/guides/gs/ messages-jms /
我需要在发送其他任何消息之前先发送一些优先级更高的消息。

I am following this guide- https://spring.io/guides/gs/messaging-jms/ I have few messages with higher priority that needs to be sent before any other message.

我已经尝试过以下操作-

I have already tried following -

jmsTemplate.execute(new ProducerCallBack(){
 public Object doInJms(Session session,MessageProducer producer){
   Message hello1 =session.createTextMessage("Hello1");
   producer.send(hello1, DeliveryMode.PERSISTENT,0,0); // <- low priority

   Message hello2 =session.createTextMessage("Hello2");
   producer.send(hello1, DeliveryMode.PERSISTENT,9,0);// <- high priority
 }
})

但是消息是按代码中的顺序发送的。我在这里缺少什么?

But the messages are sent in order as they are in the code.What I am missing here?

谢谢。

推荐答案

有很多因素可能会影响到达l使用优先级时的消息顺序。第一个问题是您是否启用了优先支持,第二个问题是在您发送消息时是否有消费者在线。

There are a number of factors that can influence the arrival order of messages when using priority. The first question would be did you enable priority support and the second would be is there a consumer online at the time you sent the message.

关于在ActiveMQ中使用优先消息的信息很多,这里是一个。请记住,如果在您发送这些消息时在线上有一个活跃的消费者,那么代理将在它们到达后立即对其进行分发,并且消费者当然会按照该顺序对其进行处理。

There are many good resources for information on using prioritized messages with ActiveMQ, here is one. Keep in mind that if there is an active consumer online when you sent those messages then the broker is just going to dispatch them as they arrive since and the consumer will of course process them in that order.

这篇关于如何使用Spring JmsTemplate为嵌入式activeMQ设置消息优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆