This content has been marked as final. Show 4 replies
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?
Your exception is surprisingI 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.
Sheeraz Junejo wrote: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.
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
java.lang.IllegalArgumentException: The property name 'time-to-live' is not a valid java identifier.
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Look at the javadoc for javax.jms.Message
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.
Thanks mate :). Just tested by setting up the property as 'TTL' and it worked.