#1587 Support routing for Message<T> parameters in @SqsHandler#1644
Open
alexisgra wants to merge 1 commit into
Open
#1587 Support routing for Message<T> parameters in @SqsHandler#1644alexisgra wants to merge 1 commit into
alexisgra wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
When using
@SqsListenerwith multiple@SqsHandlermethods, routing is unable to route messages to a handler withMessage<T>envelope as parameter.The cause is in
CompositeInvocableHandler.isPayloadAssignable: for aMessage<T>parameter it comparedthe payload against
Message.class, which never matches a concrete payload. So the handler was never selected. Following Tomas comment in #1587 , the fix detects aMessagetyped parameter and resolves its generic type, then matches the payload against that generic instead.Because a
Message<T>parameter is now considered payload-assignable, a single handler that declares both the Pojo and its Message (the workaround suggested in #1587) now resolves two payload-assignable parameters and throws"Ambiguous payload parameter for ..."instead of routing on the Pojo.handle(Pojo)handle(Message<Pojo>)handle(Pojo, Message<Pojo>)A change in
findCandidatemethod can make the last case route on the Pojo again (treatMessage<T>as theenvelope, not a second payload). I've left it out so you can decide the intended semantics.
The behavior is pinned by
throwsWhenPayloadAndMessageParametersOnSameMethod.💡 Motivation and Context
Fix #1587
💚 How did you test it?
Added unit tests in
CompositeInvocableHandlerTestcovering :Message<T>routing.Message<T>handler match the same payload type.Message<T>parameter of the same type.Added integration test in
SqsIntegrationTests, asserting aMessage<String>handler is selected and the default handler is not invoked.📝 Checklist
🔮 Next steps
Decide the intended behavior for a handler declaring both a
Pojoand aMessage<Pojo>as parameters:Message<T>as the envelope.In my opinion,
handle(Message<Pojo>)should now replacehandle(Pojo, Message<Pojo>); the dual-parameterform becomes redundant once the envelope routes on its own. However, since the workaround was publicly
documented, I understand you may prefer to avoid a breaking change here.
I'm happy to push an adjustment for 2, if that's preferred.