Results 1 to 10 of 17

Thread: Setting message priority inside message converter

Hybrid View

  1. #1

    Question Setting message priority inside message converter

    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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    What do you mean by "not working". Are you actually not seeing the priority property on the result Message? or are you not seeing the expected behavior from the JMS broker?

  3. #3

    Post Seeing the default priority instead of set priority.

    QoSEnabledJmsTemplate is working. But not sure why I couldn't see the priority getting reflected on Gems.
    Last edited by srikanthradix; Jun 24th, 2010 at 09:00 AM. Reason: Working

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    If you can reproduce this with a test case, then please create a JIRA issue and attach it. Or, if it turns out that something else is wrong (perhaps you just didn't have qos enabled before?), it would be good to know that as well.

    Thanks,
    Mark

  5. #5
    Join Date
    Sep 2010
    Posts
    1

    Default

    The second example can't work. Setting the priority of a javax.jms.Message prior to sending has no practical effect according to the javadoc:
    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.

  6. #6
    Join Date
    Jun 2010
    Location
    Paris
    Posts
    106

    Default

    I can confirm that this doesn't work with the following JMS template in spite of the explicitQosEnabled set to true.

    But I have noticed that not only the priority (JMSPriority) is not set in the JMS headers (I have checked on the JMS server directly), but also the timeToLive property (JMSExpiration). [EDIT: Other JMS headers may also be concerned but I haven't checked as this looks like a general issue]
    However, the MessageHeaders ($file_name, $timestamp, ...) are correctly set.

    Code:
    <bean id="testJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="connectionFactoryQueueMce" />
    	<property name="destinationResolver" ref="destinationResolverMce" />
    	<property name="defaultDestinationName" value="MCEHoldingForexErrorQueue" />
    	<property name="explicitQosEnabled" value="true" />
    	<property name="priority" value="9" />
    	<property name="timeToLive" value="20000" />
    </bean>
    Pierre

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •