Skip to content

JMSTemplate.receive() and receiveSelected() don't use "receiveTimeout" property if in a transaction [SPR-10109] #14742

Closed
@spring-projects-issues

Description

@spring-projects-issues

Dominique Loiseau opened SPR-10109 and commented

Hi,

I've been struggling with this (IMO) strange behavior of JMSTemplate :

protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException {
try {
// Use transaction timeout (if available).
long timeout = getReceiveTimeout();
JmsResourceHolder resourceHolder =
(JmsResourceHolder) TransactionSynchronizationManager.getResource(getConnectionFactory());
if (resourceHolder != null && resourceHolder.hasTimeout()) {

			timeout = resourceHolder.getTimeToLiveInMillis();

		}

We can see that "getReceiveTimeout()" is used to retrieve the "receiveTimeout" configurable property, but then this is not used if resourceHolder exists and has a timeout (which seems to be transaction timeout minus elapsed time in transaction).

I understand that the receiveTimeout should not exceed transaction timeout, but then isn't that better to have :

timeout = Math.min(timeout, resourceHolder.getTimeToLiveInMillis());

instead of :

timeout = resourceHolder.getTimeToLiveInMillis();

?


Affects: 2.5.6

Referenced from: commits 39fe8ee, d3da2ed

Backported to: 3.1.4

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions