Announcement Announcement Module
Collapse
No announcement yet.
Adding message priority for message put into the Queue. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding message priority for message put into the Queue.

    We tried two things to set message priority

    first is JMS Template

    Code:
            <util:constant id="common.deliveryMode" static-field="javax.jms.Message.DEFAULT_DELIVERY_MODE"/>
        <util:constant id="common.timeToLive" static-field="javax.jms.Message.DEFAULT_TIME_TO_LIVE"/>
            
            <bean id="common.qosEnabledTopicJmsTemplate" abstract="true" class="com.xx.QoSEnabledJmsTemplate">
                    <property name="connectionFactory" ref="common.topicConnectionFactory"/>
                    <property name="explicitQosEnabled" value="true"/>
                    <property name="priority" value="7"/>
                    <property name="deliveryMode" ref="common.deliveryMode"/>
                    <property name="timeToLive" ref="common.timeToLive"/>
            </bean>        
    
    
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageProducer;
    
    import org.springframework.jms.core.JmsTemplate;
    
    public class QoSEnabledJmsTemplate extends JmsTemplate {
            
            protected void doSend(MessageProducer producer, Message message) throws  JMSException {
                    System.out.println("Params while sending = DM" + getDeliveryMode() + " Priority" + message.getJMSPriority() + " TTL"+ getTimeToLive());
                    System.out.println("QOS status =" + isExplicitQosEnabled());
                    setPriority(message.getJMSPriority());
                    producer.setPriority(message.getJMSPriority());
                    producer.send(message, getDeliveryMode(), message.getJMSPriority(), getTimeToLive());
            }        
    
    }
    Second is directly setting message priority inside MessageConverter

    Code:
        @Override
        public Message toMessage(Object o, Session session)
                throws JMSException, MessageConversionException
        {
                    MTO mto =(MTO) o;
    	        BytesMessage msg = session.createBytesMessage();
    	        msg.writeBytes(mto.toByteArray());
                    msg.setJMSPriority(1);
            	return msg;
            }
    Both of them are not working. Please suggest.

  • #2
    Use MessagePostProcessor

    Code:
     public class MyPostProcessor implements MessagePostProcessor {
            private int priority;
            public int getPriority() {
                return priority;
            }
            public void setPriority(int priority) {
                this.priority = priority;
            }
            public Message postProcessMessage(final Message msg) throws JMSException {
                msg.setJMSPriority(priority);
                return msg;
            }
        }
    use jmsTemplate convertAndSend(msg, converter);

    Comment

    Working...
    X