Completion of ACTION-231: Come up with a concrete proposal to resolve issue 68

I have reviewed the mail in which Andrew Kennedy raises ISSUE-68 [1] and I
recommend that we adopt his proposal with some slight modifications.

The original sample attempts to show different techniques for setting JMS
Message header properties: It uses the method of setting properties on the
Message (incorrect because  the values are ignored) and the MessageProducer
(which is valid), and it uses the (correct but commented out) method of
passing the properties to the 4 parameter MessageProducer.send() method.
Andrew proposes that we just use the 4 parameter MessageProducer.send()
method.

My revised proposal is that we continue to show both valid techniques for
setting header properties, but instead of (incorrectly) setting some
properties on the Message, we set all the properties on the MessageProducer
[2].

Specifically, in the code sample in Section 2.2.2.1 we should replace the
jmsMessage.setJMSDeliveryMode() call with producer.setDeliveryMode(), and
jmsMessage.setJMSPriority() with producer.setPriority().

This means that the following code...

     public void someMethod(Context ctx, MessageProducer producer, Message
   jmsMessage,
           String deliveryModeStr, String replyToName, int priority, long
   timeToLive) {

       // set the delivery mode to the appropriate constant value.
       int deliveryMode = deliveryModeStr.equals("PERSISTENT")
         ? DeliveryMode.PERSISTENT: DeliveryMode.NON_PERSISTENT;
       jmsMessage.setJMSDeliveryMode( deliveryMode );

       // Set the reply destination, first looking it up using JNDI
       Destination replyDestination = ctx.lookup(replyToName);
       jmsMessage.setJMSReplyTo(replyDestination);

       // set the priority on the message.
       jmsMessage.setJMSPriority(priority);

       // set when the message is set to expire.
       producer.setTimeToLive(timeToLive);

       // and finally, send the message.
       producer.send(jmsMessage);

       // alternately, a bunch of the lines above could be collapsed to:
       // producer.send(jmsMessage, deliveryMode, priority, timeToLive);
    }


...will become...

     public void someMethod(Context ctx, MessageProducer producer, Message
   jmsMessage,
           String deliveryModeStr, String replyToName, int priority, long
   timeToLive) {


       // Set the reply destination, first looking it up using JNDI
       Destination replyDestination = ctx.lookup(replyToName);
       jmsMessage.setJMSReplyTo(replyDestination);

       // set the delivery mode to the appropriate constant value.
       int deliveryMode = deliveryModeStr.equals("PERSISTENT")
         ? DeliveryMode.PERSISTENT: DeliveryMode.NON_PERSISTENT;
       producer.setDeliveryMode( deliveryMode );

       // set the default priority on the producer.
       producer.setPriority(priority);

       // set when the message is set to expire.
       producer.setTimeToLive(timeToLive);

       // and finally, send the message.
       producer.send(jmsMessage);

       // Alternately, instead of changing the producer's default settings,
   the
       // header properties could be set on a per-message basis by passing
   them
       // to the MessageProducer.send() method, like so:
       // producer.send(jmsMessage, deliveryMode, priority, timeToLive);
    }

This completes ACTION-231.

Regards
Mark

[1] http://lists.w3.org/Archives/Public/public-soap-jms/2010Nov/0021.html
[2] http://download.oracle.com/javaee/5/api/javax/jms/MessageProducer.html

Received on Tuesday, 7 December 2010 13:57:20 UTC