How to set message priority for embedded activeMQ using spring JmsTemplate?

谁说胖子不能爱 提交于 2019-12-11 14:48:43

问题


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?

Thank you.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/56111337/how-to-set-message-priority-for-embedded-activemq-using-spring-jmstemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!