Skip to content

Make SendToMethodReturnValueHandler and SubscriptionMethodReturnValueHandler customizable, to allow for pass-through of message headers#36179

Closed
catturtle123 wants to merge 1 commit intospring-projects:mainfrom
catturtle123:main
Closed

Make SendToMethodReturnValueHandler and SubscriptionMethodReturnValueHandler customizable, to allow for pass-through of message headers#36179
catturtle123 wants to merge 1 commit intospring-projects:mainfrom
catturtle123:main

Conversation

@catturtle123
Copy link
Contributor

@catturtle123 catturtle123 commented Jan 20, 2026

This PR addresses issue #36168

Summary

  • Added an opt-in mechanism to selectively propagate headers from an input Message to the outbound Message created by:

    • SendToMethodReturnValueHandler
    • SubscriptionMethodReturnValueHandler
  • Header propagation is controlled via a configurable Predicate<String>.

  • Default behavior remains unchanged: no headers are propagated unless explicitly configured.

Resolved Issue

  • Allows applications to forward selected headers (e.g. correlation or receipt-related headers) while avoiding accidental propagation of internal or protocol-specific headers.
  • Provides a simple and explicit customization point instead of always copying or discarding headers.

Scope

  • This change applies only at the Spring Messaging layer.
  • It affects how outbound MessageHeaders are populated by handler return value processing.
  • It does not change STOMP native header serialization or WebSocket frame encoding.

Discussion Points

  • Whether the public getter (getHeaderPropagationPredicate) should be retained, or removed to keep the API strictly write-only.
  • The current scope of this PR is limited to propagating headers at the Spring Messaging level.
    A discussion point is whether this is sufficient for the intended use cases, or if extending the mechanism to STOMP native headers should be considered separately rather than as part of this change.

@rstoyanchev rstoyanchev self-assigned this Jan 20, 2026
@rstoyanchev rstoyanchev added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 20, 2026
@rstoyanchev rstoyanchev added this to the 7.0.4 milestone Jan 20, 2026
@rstoyanchev rstoyanchev changed the title Add header propagation predicate support to message return value hand… Make SendToMethodReturnValueHandler and SubscriptionMethodReturnValueHandler customizable, to allow for pass-through of message headers Jan 20, 2026
@catturtle123
Copy link
Contributor Author

catturtle123 commented Jan 20, 2026

I've applied the requested changes (renaming to headerFilter, switching to add~ method with Predicate#or logic, and adjusting the execution order). I've squashed the changes into the main commit to keep the history clean as per the contribution guide. Sorry for making the delta review slightly harder.

…lers

Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
rstoyanchev pushed a commit that referenced this pull request Feb 6, 2026
…lers

See gh-36179

Signed-off-by: Junhwan Kim <musoyou1085@gmail.com>
rstoyanchev added a commit that referenced this pull request Feb 6, 2026
@rstoyanchev
Copy link
Contributor

No problem, I added an additional property on SimpAnnotationMethodMessageHandler to make it a little easier to configure.

@catturtle123
Copy link
Contributor Author

Hi @rstoyanchev,

When I was working on this PR, I found that the propagated headers didn't actually reach the STOMP client. There are two issues:

Input side: STOMP custom headers (e.g. x-correlation-id) are stored inside the nativeHeaders sub-map, not as top-level MessageHeaders entries. So when headerFilter iterates over top-level keys, it never matches them.

Output side: Even if headers were copied to the top-level MessageHeaders, StompEncoder.writeHeaders() only serializes entries from the nativeHeaders sub-map, so they would never be written to the outbound STOMP frame.

That's why I had left it as a discussion point in the PR. Is the current scope what you intended, or should we extend propagation to STOMP native headers as well? If it makes sense to extend, I'd be happy to follow up with a PR.

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) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make SendToMethodReturnValueHandler and SubscriptionMethodReturnValueHandler customizable, to allow for pass-through of message headers

3 participants