2

I've read that if exception is thrown in the flow the first thing the framework will do is check message header for error-channel property. Is it always the case?

In my particular case I'm assigning a custom error-channel to a message header and yet the message seems to get propagated up the stream to the nearest error-handler/error-channel.

<int:chain id="buildAggregatedResponseChain" input-channel="aggregatedResultChannel"
               output-channel="sendAggregatedChannel">
        <int:header-enricher>
            <int:error-channel ref="myErrorChannel"/>
        </int:header-enricher>
        <int:service-activator ref="service" method="doSomething"/>
    </int:chain>

I explicitly throw an exception inside doSomething but the exception never ends up in myErrorChannel. Instead, it is "propagated" to the nearest ErrorHandler up the stream or to the error-channel specified up the stream for int-mail:imap-idle-channel-adapter(tried several different flows). What do I miss? Maybe someone can outline the main principal of error handling/error propagation(for example when talking about several transactions, etc)? There is some information out there, but it is quite scattered and not systematic.

yuranos
  • 8,799
  • 9
  • 56
  • 65

1 Answers1

2

It depends on the upstream flow; if there's an async handoff the header is consulted; otherwise, the exception is thrown back to the inbound endpoint.

In general, I would advise against modifying framework headers such as errorChannel. Instead put an error-channel on the inbound endpoint (such as your imap idle adapter) and handle the errors on that flow.

Modifying the headers directly is rarely needed. If you wish to insert different error-handling mid-flow then you can insert a messaging gateway...

<int:service activator ... ref="gw" />

<int:gateway id="gw" default-request-channel="..." 
    error-channel="midFlowErrorChannel" />

If the downstream flow (from the gateway) returns no result on success, then be sure to add a default reply timeout of 0 (or use a custom service interface with a method that returns void).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • "If you wish to insert different error-handling mid-flow then you can insert a messaging gateway" - that what I would ask about next:) – yuranos Apr 13 '15 at 09:38