How to set message priority for embedded activeMQ

2019-08-22 08:50发布

问题:

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.