Skip to content

Add selector type support for sendAndReceive methods in JmsOperations and JmsTemplate#36177

Closed
pisek wants to merge 4 commits intospring-projects:mainfrom
pisek:main
Closed

Add selector type support for sendAndReceive methods in JmsOperations and JmsTemplate#36177
pisek wants to merge 4 commits intospring-projects:mainfrom
pisek:main

Conversation

@pisek
Copy link
Contributor

@pisek pisek commented Jan 19, 2026

For explicit response queue we need correlationId to be used.
There are 2 main approaches depending on JMS provider:

  • CORRELATION_ID - correlationId set on request message that JMS provider copies to response message
  • MESSAGE_ID - after sending request, JMS provider assigns messageId to request message and this value is also being copied to correlationId on response message

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 19, 2026
… and JmsTemplate

Signed-off-by: Michał Pisarski <pisekfm@o2.pl>
pisek added 3 commits January 19, 2026 17:26
…til constants

Signed-off-by: Michał Pisarski <pisekfm@o2.pl>
…ssage IDs

Signed-off-by: Michał Pisarski <pisekfm@o2.pl>
Signed-off-by: Michał Pisarski <pisekfm@o2.pl>
@sbrannen sbrannen added the in: messaging Issues in messaging modules (jms, messaging) label Jan 19, 2026
@jhoeller
Copy link
Contributor

jhoeller commented Jan 19, 2026

Frankly, this adds quite a bit of complexity to the sendAndReceive overloads. At this point I wonder whether the previously introduced sendAndReceive methods without a SelectorType argument (#36162) are even useful on their own? If not, I'd rather revert that addition to 7.0.4, revisiting the topic for 7.1 instead.

If the selector type is commonly configured per provider, it should rather be a JmsTemplate-level setter rather than yet another sendAndReceive argument. Also, it is unusual for JmsTemplate to compose a selector expression - that might be an indication that the functionality should better live on top of JmsTemplate itself.

@jhoeller jhoeller self-assigned this Jan 19, 2026
@jhoeller jhoeller added the status: waiting-for-feedback We need additional information before we can continue label Jan 20, 2026
@pisek
Copy link
Contributor Author

pisek commented Jan 21, 2026

Well, they would kindof work - only when you use one thread to call JMS... so yeap - it might be misleading and unusable in common scenarios :/
I forgot to include these changes in first PR.

The setter thing - sure, i will move it to setter then.

Composing selector expression - it is rather hard to compose it on top of JmsTemplate as you need messageId that is only set after the message is sent.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 21, 2026
@jhoeller
Copy link
Contributor

jhoeller commented Jan 21, 2026

In light of this, let's drop the "none" option and use the messageId approach by default for those sendAndReceive overloads with an explicit response queue. And for a custom correlation id, the provided MessageCreator callback can call setJMSCorrelationID if it prefers that - so we could simply check for getJMSCorrelationID in the message and use that when given, otherwise use getJMSMessageID. No need for additional overloads then and no need for a configurable enum either, and the correlation id can be built in a custom way in the MessageCreator rather than baking a UUID strategy into an enum.

@jhoeller
Copy link
Contributor

@pisek I'm experimenting with my approach above, using a variation of your unit tests. No need to update the PR right now, I'll keep you posted. Let me know if you see a fundamental problem with this approach though.

@jhoeller
Copy link
Contributor

I've pushed the implicit JMSCorrelationID/JMSMessageID usage as suggested above. While a JMSCorrelationID (if desired) has to be manually set in each MessageCreator, I find that flexibility preferable over a hard-coded enum mode.

From my perspective, this removes the need for the additional method overloads with the enum in this PR. Please give this a try against the latest 7.0.4 snapshot. If anything remains for this to be usable in the 7.0.4 release, let me know.

@jhoeller jhoeller closed this Jan 21, 2026
@jhoeller jhoeller added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: messaging Issues in messaging modules (jms, messaging) status: feedback-provided Feedback has been provided status: superseded An issue that has been superseded by another

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants