user1052610
user1052610

Reputation: 4719

Error Handling in single threaded applications

In a single threaded Spring Integration, application where the entire pipleine is running within the same transaction, an error channel is not applicable. Instead, exceptions will be thrown back to the caller.

The way I am doing this is to define a service activator which is the first of a chain of components which handle an incoming message.

@ServiceActivator
public Message handleException(Message message) {
   try {
      return message;
   }
   catch (Throwable throwable){
      // HANDLE ERROR
   }
   return null;
}

Is this the correct approach, or is there a better strategy?

Thanks

Upvotes: 0

Views: 112

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

No; that won't do anything at all; it will simply pass the message to the next element in the chain. If you don't need to handle the error in any way, and just want it thrown back to the caller, you need to do nothing. If the start of the flow is a gateway, the gateway will unwrap the cause from the MessagingException.

You can, of course, put an error-channel on the gateway and handle it there.

It's generally best to provide some more details about your flow (entry point etc), when asking these general questions.

Upvotes: 1

Related Questions