You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* GH-3946: Revise Router channelKeyFallback option
Fixes#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
* Fix `IntegrationGraphServerTests` to `setChannelKeyFallback(true)` explicitly
* Remove not relevant `default-output-channel` from the `DynamicRouterTests-context.xml`
* Reject an `AbstractMappingMessageRouter` configuration where `defaultOutputChannel` 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.
* Remove `&` symbol from JavaDocs
* Fix `boolean` expression for `AbstractMappingMessageRouter` configuration check
* Fix `IntegrationGraphServerTests` for new router behavior
* Improve language in docs
Copy file name to clipboardExpand all lines: spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java
+82-13
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2002-2021 the original author or authors.
2
+
* Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter
Copy file name to clipboardExpand all lines: spring-integration-core/src/test/java/org/springframework/integration/dsl/routers/NoFallbackAllowedTests.java
+3-3
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,8 @@
33
33
34
34
/**
35
35
* @author Gary Russell
36
+
* @author Artem Bilan
37
+
*
36
38
* @since 5.2
37
39
*
38
40
*/
@@ -53,9 +55,7 @@ public static class Config {
53
55
54
56
@Bean
55
57
publicIntegrationFlowflow() {
56
-
returnf -> f.route("headers.whereTo", r -> r
57
-
.noChannelKeyFallback()
58
-
.defaultOutputChannel(queue()));
58
+
returnf -> f.route("headers.whereTo", r -> r.defaultOutputChannel(queue()));
Copy file name to clipboardExpand all lines: spring-integration-core/src/test/java/org/springframework/integration/graph/IntegrationGraphServerTests.java
Copy file name to clipboardExpand all lines: spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests-context.xml
Copy file name to clipboardExpand all lines: src/reference/asciidoc/router.adoc
+4-1
Original file line number
Diff line number
Diff line change
@@ -349,7 +349,10 @@ If set, this attribute provides a reference to the channel where messages should
349
349
If no default output channel is provided, the router throws an exception.
350
350
If you would like to silently drop those messages instead, set the default output channel attribute value to `nullChannel`.
351
351
+
352
-
NOTE: A message is sent only to the `default-output-channel` if `resolution-required` is `false` and the channel is not resolved.
352
+
NOTE: Starting with version 6.0, setting a default output channel also resets the `channelKeyFallback` option to `false`.
353
+
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.
354
+
If `channelKeyFallback` is set to `true` explicitly, the further logic depends on the `resolutionRequired` option: the message to non-resolved channel from key can reach a `defaultOutputChannel` only if `resolutionRequired` is `false`.
355
+
Therefore, a configuration where `defaultOutputChannel` is provided and both `channelKeyFallback` & `resolutionRequired` are set to `true` is rejected by the `AbstractMappingMessageRouter` initialization phase.
353
356
354
357
`resolution-required`::
355
358
This attribute specifies whether channel names must always be successfully resolved to channel instances that exist.
Copy file name to clipboardExpand all lines: src/reference/asciidoc/whats-new.adoc
+5
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,11 @@ For convenience, the XML and Java DSL for Scatter-Gather, based on the `Recipien
110
110
111
111
See <<./scatter-gather.adoc#scatter-gather,Scatter-Gather>> for more information.
112
112
113
+
Another convenient behavior change has been made to the `AbstractMappingMessageRouter`.
114
+
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 message to the `defaultOutputChannel`.
115
+
116
+
See <<./router.adoc#router-common-parameters-all,Router Options>> for more information.
117
+
113
118
The `AggregatingMessageHandler` now does not split a `Collection<Message<?>>` result of the `MessageGroupProcessor` (unless it is a `SimpleMessageGroupProcessor`) on the output, but emits a single message containing this whole collection as a payload.
114
119
115
120
See <<./aggregator.adoc#aggregator,Aggregator>> for more information.
0 commit comments