GH-3131 Invoke full ChannelInterceptor contract in DefaultPollableMessageSource - #3253
Open
akenra wants to merge 1 commit into
Open
GH-3131 Invoke full ChannelInterceptor contract in DefaultPollableMessageSource#3253akenra wants to merge 1 commit into
akenra wants to merge 1 commit into
Conversation
…tPollableMessageSource Signed-off-by: akenra <37288280+akenra@users.noreply.github.com>
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.
Context
DefaultPollableMessageSourcecurrently invokes only thepreSendmethod of registeredChannelInterceptors (via an AOP advice aroundMessageSource.receive()). As discussed in #3131, @artembilan agreed to implement the rest of theChannelInterceptorcontract on pollable sources while retainingpreSendfor backward compatibility ("it won't hurt to implement the rest of ChannelInterceptor contracts in the PollableMessageSource").What this PR implements
Receive phase (around
MessageSource.receive()):preReceive(channel)gate before retrieval: if any interceptor returnsfalse, no receive is attempted and (per its javadoc precondition)afterReceiveCompletionis not invoked.postReceive(message, channel)after retrieval: may transform the message; returningnulldrops it.afterReceiveCompletion(message, channel, ex)in a finally block once thepreReceivechain has passed.Handling phase (in
poll()):postSend(message, channel, true)only after successful handling.afterSendCompletion(message, channel, sent, ex)exactly once infinally, wheresentistrueonly when no failure was recorded; handled-error paths (error channel) record the exception while still returningtruefrompoll().Lifecycle order for a successful poll:
Bonus fix:
setSource()used to snapshot the interceptor list at wiring time, silently ignoring interceptors added afterwards. The advice now reads a live view.Backward compatibility
preSendkeeps its exact position and semantics; all 14 tests of the existing interceptor-drivenPollableConsumerTestspass unmodified.ChannelInterceptors on pollable sources (verified), so the affected surface is user interceptors only.Testing
DefaultPollableMessageSourceTests(6 tests): exact lifecycle ordering,preReceive=falseshort-circuit,postReceive=nulldrop, handled-error completion with exception marker and skippedpostSend, lateaddInterceptor()now honored, legacy null-preSendabort preserved. All went red before the fix and green after.core/spring-cloud-streamfull suite 40 tests / 0 failures;PollableConsumerTests14/14 andPollableSourceTests5/5.Resolves #3131
Notes for reviewers
postReceivereturningnullis treated as dropping the message entirely (mirroring pollable-channel behavior). If the preferred semantics are skip-only-that-interceptor, happy to adjust.afterSendCompletion'ssentflag istrueiff no failure was recorded - on handled-error pathspoll()returnstruebut the hook still sees the exception.RecoveryCallbackpath test, and the longer-term idea from DefaultPollableMessageSource should executepostSendandafterSendCompletioninterceptor methods #3131 of a dedicated non-ChannelInterceptorabstraction for pollables.