-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-3946: Revise Router channelKeyFallback option #3948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly docs, but one important.
* Use the next, after router, parent flow {@link MessageChannel} as a | ||
* {@link AbstractMessageRouter#setDefaultOutputChannel(MessageChannel)} of this router. | ||
* This option also disables {@link AbstractMappingMessageRouter#setChannelKeyFallback(boolean)}, | ||
* if not called explicitly, to skip an attempt to resolve channel name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* if not called explicitly, to skip an attempt to resolve channel name. | |
* if not called explicitly afterwards, to skip an attempt to resolve the channel name. |
* Set the default channel where Messages should be sent if channel resolution | ||
* fails to return any channels. | ||
* It also sets {@link #channelKeyFallback} to {@code false} to avoid | ||
* an attempt to resolve a channel from its key, but instead send message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* an attempt to resolve a channel from its key, but instead send message | |
* an attempt to resolve a channel from its key, but instead send the message |
* an attempt to resolve a channel from its key, but instead send message | ||
* directly to this channel. | ||
* If {@link #channelKeyFallback} is set explicitly to {@code true}, | ||
* the further logic depend on a {@link #resolutionRequired} options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* the further logic depend on a {@link #resolutionRequired} options | |
* the logic depends on the {@link #resolutionRequired} option |
* The configuration where default output channel is present and | ||
* {@link #resolutionRequired} and {@link #resolutionRequired} are set to {@code true} | ||
* is rejected since it leads to ambiguity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The configuration where default output channel is present and | |
* {@link #resolutionRequired} and {@link #resolutionRequired} are set to {@code true} | |
* is rejected since it leads to ambiguity. | |
* The configuration where a default output channel is present and | |
* {@link #setResolutionRequired resolutionRequired} and | |
* {@link #setChannelKeyFallback channelKeyFallback} are set to {@code true} | |
* is rejected since it leads to ambiguity. |
* this default output channel may never happen. | ||
* The configuration where default output channel is present and | ||
* {@link #resolutionRequired} and {@link #resolutionRequired} are set to {@code true} | ||
* is rejected since it leads to ambiguity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same changes here.
"The 'defaultOutputChannel' cannot be reached " + | ||
"when both 'channelKeyFallback' & 'resolutionRequired' are set to true. " + | ||
"See their javadocs for more information."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can enforce this; what if both are true and channel resolution is successful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. And what is the reason to have a defaultOutputChannel
then?
You simply can set channelKeyFallback = true
, but resolutionRequired = false
.
So, if resolution is OK, we go there, if it is not we fallback to a default channel.
We probably can improve docs for this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doh; of course.
src/reference/asciidoc/router.adoc
Outdated
NOTE: Starting with version 6.0, setting a default output channel also resets `channelKeyFallback` option to `false`. | ||
So, no attempts to resolve a channel from name, but rather fallback to this default output channel - similar to Java `switch` statement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Starting with version 6.0, setting a default output channel also resets `channelKeyFallback` option to `false`. | |
So, no attempts to resolve a channel from name, but rather fallback to this default output channel - similar to Java `switch` statement. | |
NOTE: Starting with version 6.0, setting a default output channel also resets the `channelKeyFallback` option to `false`. | |
So, no attempts will be made to resolve a channel from its name, but rather fallback to this default output channel - similar to a Java `switch` statement. |
src/reference/asciidoc/router.adoc
Outdated
If `channelKeyFallback` is set to `true` explicitly, the further logic depends on the `resolutionRequired` option: the message can reach a `defaultOutputChannel` only if `resolutionRequired` is `false`. | ||
Therefore, a configuration where `defaultOutputChannel` is provided and both `channelKeyFallback` & `resolutionRequired` are set to `true` is rejected by the `AbstractMappingMessageRouter` initialization phase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't enforce this. See comment above.
Another convenient behaviour change has been done for an `AbstractMappingMessageRouter`. | ||
Now setting a `defaultOutputChannel` also resets a `channelKeyFallback` to `false`, so no attempts to resolve channel from its key, but immediate fallback to `defaultOutputChannel`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another convenient behaviour change has been done for an `AbstractMappingMessageRouter`. | |
Now setting a `defaultOutputChannel` also resets a `channelKeyFallback` to `false`, so no attempts to resolve channel from its key, but immediate fallback to `defaultOutputChannel`. | |
Another convenient behavior change has been made to the `AbstractMappingMessageRouter`. | |
Now, setting a `defaultOutputChannel` also resets the `channelKeyFallback` property to `false`, so no attempts will be made to resolve a channel from its key, but the logic immediately falls back to sending the mesage to the `defaultOutputChannel`. |
Fixes spring-projects#3946 The `AbstractMappingMessageRouter` has both `resolutionRequired` and `channelKeyFallback` as `true` by default. End-users expects them to back off when they set a `defaultOutputChannel`. They really want something similar to Java `switch` statement * Change the logic in the `AbstractMappingMessageRouter` to reset `channelKeyFallback` to `false` when `defaultOutputChannel` to avoid attempts to resolve channel from name, but rather fallback to `defaultOutputChannel` as it states from th mentioned Java `switch` statement experience * Deprecate `RouterSpec.noChannelKeyFallback()` in favor of newly introduced `channelKeyFallback(boolean)` * Call `channelKeyFallback(false)` from an overloaded `defaultOutputToParentFlow()` to reflect the mentioned expected behavior in Java DSL as well. * Respectively, deprecate `KotlinRouterSpec.noChannelKeyFallback()` wrapper in favor of newly introduced `channelKeyFallback(channelKeyFallback: Boolean)` * Remove redundant already `noChannelKeyFallback()` option in the `NoFallbackAllowedTests` * Document the change and new behavior
…ests-context.xml`
…OutputChannel` is provided and both `channelKeyFallback` & `resolutionRequired` are set to `true`. Such a state makes `defaultOutputChannel` as not reachable and may cause some confusions in target applications.
I don't think we need to say anything else.
|
My point with this change is that end-users expects a behavior a-la Java |
Fixes #3946
The
AbstractMappingMessageRouter
has bothresolutionRequired
andchannelKeyFallback
astrue
by default.End-users expects them to back off when they set a
defaultOutputChannel
. They really want something similar to Javaswitch
statementAbstractMappingMessageRouter
to resetchannelKeyFallback
tofalse
whendefaultOutputChannel
to avoid attempts to resolve channel from name, but rather fallback todefaultOutputChannel
as it states from th mentioned Javaswitch
statement experienceRouterSpec.noChannelKeyFallback()
in favor of newly introducedchannelKeyFallback(boolean)
channelKeyFallback(false)
from an overloadeddefaultOutputToParentFlow()
to reflect the mentioned expected behavior in Java DSL as well.KotlinRouterSpec.noChannelKeyFallback()
wrapper in favor of newly introducedchannelKeyFallback(channelKeyFallback: Boolean)
noChannelKeyFallback()
option in theNoFallbackAllowedTests