Hi,
I'm using spring-jms
version 4.3.30.RELEASE (though my problems even remain on the latest version; the code didn't change) and trying to set the expiration time (TTL) on the MessageProducer
. I know, per message is not recommended.
Setting setExplicitQosEnabled(true)
and setMessageTimestampEnabled(true)
doesn't` seem to help in my case.
This the relevant Code in JmsTemplate
:
protected MessageProducer createProducer(Session session, Destination destination) throws JMSException {
MessageProducer producer = doCreateProducer(session, destination);
if (!isMessageIdEnabled()) {
producer.setDisableMessageID(true);
}
if (!isMessageTimestampEnabled()) {
producer.setDisableMessageTimestamp(true);
}
return producer;
}
I would like to set producer.setDisableMessageTimestamp(true)
to false
which doesn't seem to work, since there is no setter to do that in JmsTemplate
directly. It also seems to default to true
in MessageProducer
. Hence, TTL is never read and expiration is set to 0
in ActiveMQSession
:
protected void send(ActiveMQMessageProducer producer, ActiveMQDestination destination, Message message, int deliveryMode, int priority, long timeToLive,
MemoryUsage producerWindow, int sendTimeout, AsyncCallback onComplete) throws JMSException {
// SNIP //
long expiration = 0L;
if (!producer.getDisableMessageTimestamp()) {
long timeStamp = System.currentTimeMillis();
message.setJMSTimestamp(timeStamp);
if (timeToLive > 0) {
expiration = timeToLive + timeStamp;
}
}
message.setJMSExpiration(expiration);
// SNIP //
}
My current workaround is to override the createPrdoucer
method by extending JmsTemplate
like this:
@Override
protected MessageProducer createProducer(Session session, Destination destination) throws JMSException
{
MessageProducer producer = super.createProducer(session, destination);
producer.setDisableMessageTimestamp(false);
return producer;
}
Am I completely wrong and misusing the API and there is a better way to achieve this?
Comment From: snicoll
Am I completely wrong and misusing the API and there is a better way to achieve this?
I don't know but the API is pretty clear about the fact this is a hint for the producer that it can ignore if it does not support it. It's unclear to me why it is enabled by default for you on ActiveMQ as I can see disableMessageTimestamp
is false
in ActiveMQMessageProducer
. Can you double check with a vanilla ActiveMQ instance?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.