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
Fixes#3024
To avoid confusing about `errorChannel` header behavior and make it more
clear how to handle errors in Spring Integration flows, it would be
better to present an `Error Handling` chapter on the top level.
So, now it is a first chapter of the `Appendices` section
Copy file name to clipboardExpand all lines: src/reference/asciidoc/channel.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -951,7 +951,7 @@ If namespace support is enabled, two special channels are defined within the app
951
951
The 'nullChannel' acts like `/dev/null`, logging any message sent to it at the `DEBUG` level and returning immediately.
952
952
Any time you face channel resolution errors for a reply that you do not care about, you can set the affected component's `output-channel` attribute to 'nullChannel' (the name, 'nullChannel', is reserved within the application context).
953
953
The 'errorChannel' is used internally for sending error messages and may be overridden with a custom configuration.
954
-
This is discussed in greater detail in <<./configuration.adoc#namespace-errorhandler,Error Handling>>.
954
+
This is discussed in greater detail in <<./error-handling.adoc#error-handling,Error Handling>>.
955
955
956
956
957
957
See also <<./dsl.adoc#java-dsl-channels,Message Channels>> in the Java DSL chapter for more information about message channel and interceptors.
Copy file name to clipboardExpand all lines: src/reference/asciidoc/configuration.adoc
-75Lines changed: 0 additions & 75 deletions
Original file line number
Diff line number
Diff line change
@@ -149,81 +149,6 @@ To do so, define a bean with the appropriate JNDI name for your environment, as
149
149
150
150
The next section describes what happens if exceptions occur within the asynchronous invocations.
151
151
152
-
[[namespace-errorhandler]]
153
-
=== Error Handling
154
-
155
-
As described in the <<./overview.adoc#overview,overview>> at the very beginning of this manual, one of the main motivations behind a message-oriented framework such as Spring Integration is to promote loose coupling between components.
156
-
The message channel plays an important role, in that producers and consumers do not have to know about each other.
157
-
However, the advantages also have some drawbacks.
158
-
Some things become more complicated in a loosely coupled environment, and one example is error handling.
159
-
160
-
When sending a message to a channel, the component that ultimately handles that message may or may not be operating within the same thread as the sender.
161
-
If using a simple default `DirectChannel` (when the `<channel>` element that has no `<queue>` child element and no 'task-executor' attribute),
162
-
the message handling occurs in the same thread that sends the initial message.
163
-
In that case, if an `Exception` is thrown, it can be caught by the sender (or it may propagate past the sender if it is an uncaught `RuntimeException`).
164
-
So far, everything is fine.
165
-
This is the same behavior as an exception-throwing operation in a normal call stack.
166
-
167
-
A message flow that runs on a caller thread might be invoked through a messaging gateway (see <<./gateway.adoc#gateway,Messaging Gateways>>) or a `MessagingTemplate` (see <<./channel.adoc#channel-template,`MessagingTemplate`>>).
168
-
In either case, the default behavior is to throw any exceptions to the caller.
169
-
For the messaging gateway, see <<./gateway.adoc#gateway-error-handling,Error Handling>> for details about how the exception is thrown and how to configure the gateway to route the errors to an error channel instead.
170
-
When using a `MessagingTemplate` or sending to a `MessageChannel` directly, exceptions are always thrown to the caller.
171
-
172
-
When adding asynchronous processing, things become rather more complicated.
173
-
For instance, if the 'channel' element does provide a 'queue' child element, the component that handles the message operates in a different thread than the sender.
174
-
The same is true when an `ExecutorChannel` is used.
175
-
The sender may have dropped the `Message` into the channel and moved on to other things.
176
-
There is no way for the `Exception` to be thrown directly back to that sender by using standard `Exception` throwing techniques.
177
-
Instead, handling errors for asynchronous processes requires that the error-handling mechanism also be asynchronous.
178
-
179
-
Spring Integration supports error handling for its components by publishing errors to a message channel.
180
-
Specifically, the `Exception` becomes the payload of a Spring Integration `ErrorMessage`.
181
-
That `Message` is then sent to a message channel that is resolved in a way that is similar to the 'replyChannel' resolution.
182
-
First, if the request `Message` being handled at the time the `Exception` occurred contains an 'errorChannel' header (the header name is defined in the `MessageHeaders.ERROR_CHANNEL` constant), the `ErrorMessage` is sent to that channel.
183
-
Otherwise, the error handler sends to a "`global`" channel whose bean name is `errorChannel` (this is also defined as a constant: `IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME`).
184
-
185
-
A default `errorChannel` bean is created internally by the Framework.
186
-
However, you can define your own if you want to control the settings.
187
-
The following example shows how to define an error channel backed by a queue with a capacity of 500:
188
-
189
-
====
190
-
[source,xml]
191
-
----
192
-
<int:channel id="errorChannel">
193
-
<int:queue capacity="500"/>
194
-
</int:channel>
195
-
----
196
-
====
197
-
198
-
NOTE: The default error channel is a `PublishSubscribeChannel`.
199
-
200
-
The most important thing to understand here is that the messaging-based error handling applies only to exceptions that are thrown by a Spring Integration task that is executing within a `TaskExecutor`.
201
-
This does not apply to exceptions thrown by a handler that operates within the same thread as the sender (for example, through a `DirectChannel` as described earlier in this section).
202
-
203
-
NOTE: When exceptions occur in a scheduled poller task's execution, those exceptions are wrapped in `ErrorMessage` instances and sent to the 'errorChannel' as well.
204
-
205
-
To enable global error handling, register a handler on that channel.
206
-
For example, you can configure Spring Integration's `ErrorMessageExceptionTypeRouter` as the handler of an endpoint that is subscribed to the 'errorChannel'.
207
-
That router can then spread the error messages across multiple channels, based on the `Exception` type.
208
-
209
-
Starting with version 4.3.10, Spring Integration provides the `ErrorMessagePublisher` and the `ErrorMessageStrategy`.
210
-
You can use them as a general mechanism for publishing `ErrorMessage` instances.
211
-
You can call or extend them in any error handling scenarios.
212
-
The `ErrorMessageSendingRecoverer` extends this class as a `RecoveryCallback` implementation that can be used with retry, such as the
The `ErrorMessageStrategy` is used to build an `ErrorMessage` based on the provided exception and an `AttributeAccessor` context.
215
-
It can be injected into any `MessageProducerSupport` or `MessagingGatewaySupport`.
216
-
The `requestMessage` is stored under `ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY` in the `AttributeAccessor` context.
217
-
The `ErrorMessageStrategy` can use that `requestMessage` as the `originalMessage` property of the `ErrorMessage` it creates.
218
-
The `DefaultErrorMessageStrategy` does exactly that.
219
-
220
-
Starting with version 5.2, all the `MessageHandlingException` instances thrown by the framework components, includes a component `BeanDefinition` resource and source to determine a configuration point form the exception.
221
-
In case of XML configuration, a resource is an XML file path and source an XML tag with its `id` attribute.
222
-
With Java & Annotation configuration, a resource is a `@Configuration` class and source is a `@Bean` method.
223
-
In most case the target integration flow solution is based on the out-of-the-box components and their configuration options.
224
-
When an exception happens at runtime, there is no any end-user code involved in stack trace because an execution is against beans, not their configuration.
225
-
Including a resource and source of the bean definition helps to determine possible configuration mistakes and provides better developer experience.
As described in the <<./overview.adoc#overview,overview>> at the very beginning of this manual, one of the main motivations behind a message-oriented framework such as Spring Integration is to promote loose coupling between components.
5
+
The message channel plays an important role, in that producers and consumers do not have to know about each other.
6
+
However, the advantages also have some drawbacks.
7
+
Some things become more complicated in a loosely coupled environment, and one example is error handling.
8
+
9
+
When sending a message to a channel, the component that ultimately handles that message may or may not be operating within the same thread as the sender.
10
+
If using a simple default `DirectChannel` (when the `<channel>` element that has no `<queue>` child element and no 'task-executor' attribute), the message handling occurs in the same thread that sends the initial message.
11
+
In that case, if an `Exception` is thrown, it can be caught by the sender (or it may propagate past the sender if it is an uncaught `RuntimeException`).
12
+
This is the same behavior as an exception-throwing operation in a normal Java call stack.
13
+
14
+
A message flow that runs on a caller thread might be invoked through a messaging gateway (see <<./gateway.adoc#gateway,Messaging Gateways>>) or a `MessagingTemplate` (see <<./channel.adoc#channel-template,`MessagingTemplate`>>).
15
+
In either case, the default behavior is to throw any exceptions to the caller.
16
+
For the messaging gateway, see <<./gateway.adoc#gateway-error-handling,Error Handling>> for details about how the exception is thrown and how to configure the gateway to route the errors to an error channel instead.
17
+
When using a `MessagingTemplate` or sending to a `MessageChannel` directly, exceptions are always thrown to the caller.
18
+
19
+
When adding asynchronous processing, things become rather more complicated.
20
+
For instance, if the 'channel' element does provide a 'queue' child element (`QueueChannel` in Java & Annotations Configuration), the component that handles the message operates in a different thread than the sender.
21
+
The same is true when an `ExecutorChannel` is used.
22
+
The sender may have dropped the `Message` into the channel and moved on to other things.
23
+
There is no way for the `Exception` to be thrown directly back to that sender by using standard `Exception` throwing techniques.
24
+
Instead, handling errors for asynchronous processes requires that the error-handling mechanism also be asynchronous.
25
+
26
+
Spring Integration supports error handling for its components by publishing errors to a message channel.
27
+
Specifically, the `Exception` becomes the payload of a Spring Integration `ErrorMessage`.
28
+
That `Message` is then sent to a message channel that is resolved in a way that is similar to the 'replyChannel' resolution.
29
+
First, if the request `Message` being handled at the time the `Exception` occurred contains an 'errorChannel' header (the header name is defined in the `MessageHeaders.ERROR_CHANNEL` constant), the `ErrorMessage` is sent to that channel.
30
+
Otherwise, the error handler sends to a "`global`" channel whose bean name is `errorChannel` (this is also defined as a constant: `IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME`).
31
+
32
+
A default `errorChannel` bean is created internally by the Framework.
33
+
However, you can define your own if you want to control the settings.
34
+
The following example shows how to define an error channel in XML configuration backed by a queue with a capacity of `500`:
35
+
36
+
====
37
+
[source,xml]
38
+
----
39
+
<int:channel id="errorChannel">
40
+
<int:queue capacity="500"/>
41
+
</int:channel>
42
+
----
43
+
====
44
+
45
+
NOTE: The default error channel is a `PublishSubscribeChannel`.
46
+
47
+
The most important thing to understand here is that the messaging-based error handling applies only to exceptions that are thrown by a Spring Integration task that is executing within a `TaskExecutor`.
48
+
This does not apply to exceptions thrown by a handler that operates within the same thread as the sender (for example, through a `DirectChannel` as described earlier in this section).
49
+
50
+
NOTE: When exceptions occur in a scheduled poller task's execution, those exceptions are wrapped in `ErrorMessage` instances and sent to the 'errorChannel' as well.
51
+
52
+
To enable global error handling, register a handler on that channel.
53
+
For example, you can configure Spring Integration's `ErrorMessageExceptionTypeRouter` as the handler of an endpoint that is subscribed to the 'errorChannel'.
54
+
That router can then spread the error messages across multiple channels, based on the `Exception` type.
55
+
56
+
Starting with version 4.3.10, Spring Integration provides the `ErrorMessagePublisher` and the `ErrorMessageStrategy`.
57
+
You can use them as a general mechanism for publishing `ErrorMessage` instances.
58
+
You can call or extend them in any error handling scenarios.
59
+
The `ErrorMessageSendingRecoverer` extends this class as a `RecoveryCallback` implementation that can be used with retry, such as the
The `ErrorMessageStrategy` is used to build an `ErrorMessage` based on the provided exception and an `AttributeAccessor` context.
62
+
It can be injected into any `MessageProducerSupport` or `MessagingGatewaySupport`.
63
+
The `requestMessage` is stored under `ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY` in the `AttributeAccessor` context.
64
+
The `ErrorMessageStrategy` can use that `requestMessage` as the `originalMessage` property of the `ErrorMessage` it creates.
65
+
The `DefaultErrorMessageStrategy` does exactly that.
66
+
67
+
Starting with version 5.2, all the `MessageHandlingException` instances thrown by the framework components, includes a component `BeanDefinition` resource and source to determine a configuration point form the exception.
68
+
In case of XML configuration, a resource is an XML file path and source an XML tag with its `id` attribute.
69
+
With Java & Annotation configuration, a resource is a `@Configuration` class and source is a `@Bean` method.
70
+
In most case the target integration flow solution is based on the out-of-the-box components and their configuration options.
71
+
When an exception happens at runtime, there is no any end-user code involved in stack trace because an execution is against beans, not their configuration.
72
+
Including a resource and source of the bean definition helps to determine possible configuration mistakes and provides better developer experience.
Copy file name to clipboardExpand all lines: src/reference/asciidoc/whats-new.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,7 @@ The `Function<MessageGroup, Map<String, Object>>` strategy has been introduced f
84
84
See <<./aggregator.adoc#aggregator-api,Aggregator Programming Model>> for more information.
85
85
86
86
All the `MessageHandlingException` s thrown in the framework, includes now a bean resource and source for back tracking a configuration part in case no end-user code involved.
87
-
See <<./configuration.adoc#namespace-errorhandler,Error Handling>> for more information.
87
+
See <<./error-handling.adoc#error-handling,Error Handling>> for more information.
0 commit comments