This discussion is archived
4 Replies Latest reply: Jun 29, 2011 3:15 AM by 679871 RSS

MessageExpiry - Retrieve Message timeToLive value in Consumer/MDB

679871 Newbie
Currently Being Moderated
Hi Guys,

I have a web application which produce messages on requestQueue and wait for response on responseQueue. I am using following code to set message expiry in web application;
messageproducer.setTimeToLive(30000L);
messageproducer.send(textmessage);
this message will be consumed by my MDB where I will process the request from DB and put response (a new message) back on responseQueue with its own expiry, but the condition is that response expiry will be RequestExpiry - ProcessTime. For that I need to know the value 'timeToLive' which is part of message producer and offcourse not accessible on MDB. I tried to set message.setLongProperty('time-to-live', 30000L) (same as timeToLive for producer) but I am getting following exception [currently deploying on jBoss for testing only];
13:31:43,285 ERROR [LogInterceptor] RuntimeException in method: public abstract void javax.jms.MessageListener.onMessage(javax.jms
.Message):
java.lang.IllegalArgumentException: The property name 'time-to-live' is not a valid java identifier.
at org.jboss.jms.message.JBossMessage.checkProperty(JBossMessage.java:1082)
at org.jboss.jms.message.JBossMessage.setLongProperty(JBossMessage.java:874)
at org.jboss.jms.message.MessageProxy.setLongProperty(MessageProxy.java:386)
at com.temenos.tocf.ofsmessage.mdb.OFSMessageMDB.prepareResponse(OFSMessageMDB.java:304)
at com.temenos.tocf.ofsmessage.mdb.OFSMessageMDB.onMessage(OFSMessageMDB.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Note: Above code will run on all major application servers i.e jBoss, WebLogic, WebSphere and Glassfish_

Am I missing something? Or is there any other best practice I can adopt to achieve this.

Your help and comments will be appreciated.

Regards,

--

SJunejo
  • 1. Re: MessageExpiry - Retrieve Message timeToLive value in Consumer/MDB
    ramp Explorer
    Currently Being Moderated
    Your exception is surprising. Nevertheless is there a reason you cannot add this to the message body?
    Alternatively if the value is going to be the same for all messages, why not externalize it to a property file from where both the producer and the listener can read from?
  • 2. Re: MessageExpiry - Retrieve Message timeToLive value in Consumer/MDB
    679871 Newbie
    Currently Being Moderated
    Your exception is surprising
    I know, couldn't understand, but in my producer/consumer I am using 'set/get'StringProperty successfully. I think, I have to use the same for timeToLive.
    Nevertheless is there a reason you cannot add this to the message body?
    It does not seems like a good option because then I have to parse my message in MDB (consumer) which is not very efficient and handy.
    Alternatively if the value is going to be the same for all messages, why not externalize it to a property file from where both the producer and the listener can read from?
    Requirement is to keep things simple without adding any other configuration files, besides that both producer and consumer does not share any configuration (they are independent) and we have an option (methods) to achieve this so why shouldn't we use it. Also, there can be many producer and each message can have different TTL (depends on producer) but consumer will remain one. Also on producer side the property will actually come from a properties (config) file anyway.

    It does make sense if I set timeToLive for a 'response == request' is it?. Following is currently working fine;
    jmsMsg.setStringProperty("PRINCIPAL", principal);
    So, I can set as follows and do the casting :-(;
    jmsMsg.setStringProperty("TIME_TO_LIVE", "30000L");
    Let me know if you think of any other option. I will give 'set/get'LongProperty one more try.

    Regards,

    --

    SJunejo
  • 3. Re: MessageExpiry - Retrieve Message timeToLive value in Consumer/MDB
    nigeldeakin Explorer
    Currently Being Moderated
    Sheeraz Junejo wrote:
    I tried to set message.setLongProperty('time-to-live', 30000L) (same as timeToLive for producer) but I am getting following exception [currently deploying on jBoss for testing only];
    13:31:43,285 ERROR [LogInterceptor] RuntimeException in method: public abstract void javax.jms.MessageListener.onMessage(javax.jms
    .Message):
    java.lang.IllegalArgumentException: The property name 'time-to-live' is not a valid java identifier.
    at org.jboss.jms.message.JBossMessage.checkProperty(JBossMessage.java:1082)
    at org.jboss.jms.message.JBossMessage.setLongProperty(JBossMessage.java:874)
    at org.jboss.jms.message.MessageProxy.setLongProperty(MessageProxy.java:386)
    at com.temenos.tocf.ofsmessage.mdb.OFSMessageMDB.prepareResponse(OFSMessageMDB.java:304)
    at com.temenos.tocf.ofsmessage.mdb.OFSMessageMDB.onMessage(OFSMessageMDB.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    That's because 'time-to-live' is not a valid property name, since it contains hyphens. You'd get similar errors with other JMS providers.

    Look at the javadoc for javax.jms.Message
    http://download.oracle.com/javaee/6/api/javax/jms/Message.html

    This states that "Property names must obey the rules for a message selector identifier", and the rules for a message selector identifier (further down in the same javadoc) are "identifier is an unlimited-length sequence of letters and digits, the first of which must be a letter. A letter is any character for which the method Character.isJavaLetter returns true. This includes '_' and '$'. A letter or digit is any character for which the method Character.isJavaLetterOrDigit returns true. "

    So you can't have hyphens in property names. So the fix is simple - use a different name for your property.

    Nigel
  • 4. Re: MessageExpiry - Retrieve Message timeToLive value in Consumer/MDB
    679871 Newbie
    Currently Being Moderated
    Thanks mate :). Just tested by setting up the property as 'TTL' and it worked.

    Regards,

    --

    SJunejo

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points