3 Replies Latest reply on Jul 22, 2011 7:51 AM by Yong Hao Gao

    JMS message priority not working on Message

    Ritesh Ranpara Newbie

      I was need to set message priority so that High priority message will be consumed first than Low priority message by Receivers.

      First I tried with message.setJMSPriority() method to set the priority but it was not working in HornetQ and ActiveMQ so finally I set the priority of the Message Producer using setPriority() method and it works fine now.

      My question is why Messsge.setJMSPriority() is not working in none of the JMS vendor and Why we need to set the priority of the Producer not the message itself to set the priority of the message ? What is the use of Messsge.setJMSPriority() method then ?

      Any suggestion or comment is appreciated.

      Thanks in advance.

        • 1. Re: JMS message priority not working on Message
          Yong Hao Gao Master

          I think you need to use MessageProducer's method:

           

          public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException

          to do it.

           

          See the api doc:

           

          JMS providers set this field when a message is sent. This method can be used to change the value for a message that has been received.

           

          It says this method is used by JMS providers, or used on a received message.

           

           

          Howard

          1 of 1 people found this helpful
          • 2. Re: JMS message priority not working on Message
            Ritesh Ranpara Newbie

            Hi Yong,

            Thanks for reply, that's correct I am doing in that way only,

            but then what is the use or role of Message.setJMSPriority() method ?


            • 3. Re: JMS message priority not working on Message
              Yong Hao Gao Master

              Hi Ritesh,

               

              I'm not sure about it. As far as I know this method is used internally in JMS provider to set the priority in sending. Looking at JMS spec, there is a paragraph that I think may be relevant to this method:

               

              3.4.12 Overriding Message Header Fields

              JMS permits an administrator to configure JMS to override the client-specified

              values for JMSDeliveryMode, JMSExpiration and JMSPriority. If this is done, the

              header field value must reflect the administratively specified value.

              JMS does not define specifically how an administrator overrides these header

              field values. A JMS provider is not required to support this administrative

              option.

               

              So I think it is possible for a JMS provider like hornetq to provide some admin interface to change the priority, and this method may be used for that purpose.