2

I am new to spring integration. As part of one of my tasks, I am supposed to have a default error handling mechanism for any failure in the pipeline.

I have a file inbound channel adapter as a starting point which I has been written as follows:

<int-file:inbound-channel-adapter id="inbound.jms.adapter" 
     directory="C:\Test
     channel="testChannel"
     auto-startup="false">
     <int:poller fixed-rate="1000" error-channel="default-error-channel" />
</int-file:inbound-channel-adapter>

The channel will be used further by different components.

My question is, in case of any failure further, will the exception fallback to default error channel?

Stewartside
  • 20,378
  • 12
  • 60
  • 81
Amit Ware
  • 81
  • 1
  • 4

1 Answers1

0

My question is, in case of any failure further, will the exception fallback to default error channel?

No, not fully. If your downstream is direct (composed only with DirectChannels), then yes: all exceptions will be thrown to that default-error-channel on this first polling channel adapter.

But if transfer you message to different channels (QueueChannel, ExecutorChannel) the exception will be handled via their mechanism. In most cases it is default errorChannel from the Spring Integration.

See more info here.

In addition there is ExpressionEvaluatingRequestHandlerAdvice with the exception handling feature for the particular endpoint.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks Artem. Am I correct in assuming that by having a service activator to 'erorChannel' will provide a global catch block of any exception that happens in the application. – Amit Ware Mar 19 '15 at 06:22
  • True. But as I said: it will work until you don't transfer message to the non-direct channel. It works here like `try...catch` in pure Java: if you start a new Thread within that block, its exceptions won't be available for your root `try...catch` – Artem Bilan Mar 19 '15 at 06:26
  • Ok. Thank you. If I am passing the message to non-direct channels, I would then need to explicitly mentione error-channel. Am I correct? I have something like th – Amit Ware Mar 19 '15 at 07:01
  • Ok. Thank you. If I am passing the message to non-direct channels, I would then need to explicitly mentione error-channel. Am I correct? I have something like this at the moment – Amit Ware Mar 19 '15 at 07:08
  • The service activator on inbound.jms.channel throws an exception which I hoping will be caught in the service activator on errorChannel. But it is not happening. Why is it not falling to global errorChannel? – Amit Ware Mar 19 '15 at 07:08
  • Please, edit your question for better readability. You can try to use `error-channel` header for the message. And framework uses `MessagePublishingErrorHandler` to determine the target `channel` in particular case. – Artem Bilan Mar 19 '15 at 07:13
  • Apologies for edit issue. So if I enrich my messge with error-channel, this enrichment will flow thoughout the application and Sping in case of any exception will put the exception on this error-channel. Having service activator on this channel, I can then read the exceptions and do what ever I want to. Am I correct please? – Amit Ware Mar 19 '15 at 07:23
  • Right. But it doesn't work for all cases. E.g. `` does that with a bit different way. From other side be sure that your `errorHandler` `` is listening to your appropriate error channel, not the default `errorChannel`. – Artem Bilan Mar 19 '15 at 07:25