srbhvatsa
srbhvatsa

Reputation: 98

How to handle errors in multiple flows?

I have some 4-5 flows in same config-xml and I want to handle errors in those flows in same way to avoid the redundency. So what i did is.. Created a global exception strategy and just used it to refer to all the flows. But is there a better option to do that? Like copying some message processors of flows in the subflows and then attaching a exception strategy to those subflows?

Upvotes: 0

Views: 1694

Answers (2)

Ryan Hoegg
Ryan Hoegg

Reputation: 2475

You have several options. You can define a default global exception strategy, and one or more global exception strategies. This can be somewhat inflexible as you noticed, but we have a few patterns to allow the right amount of flexibility and reuse without duplicating flow logic.

You can use private flows to encapsulate shared flow logic that also shares the same error handling. A private flow is simply a flow that doesn't have a message source. If the private flow has an exception strategy, it will be used instead of the calling flow's exception strategy.

One other way you can modularize error handling code is to use flow-ref inside an exception strategy. Perhaps you have different kinds of errors that need to share only some behavior, such as logging an error a certain way and sending a message to a dead letter queue. Each exception strategy can do it's own processing, transform its message and/or exception to a common model, and then flow-ref the shared behavior.

Upvotes: 1

Víctor Romero
Víctor Romero

Reputation: 5115

There is no better way than that. Subflows do not allow exception handlers.

What is often used when all the flows share a single message source, is to put an exception handler on the flow with the message source and nothing on the rest that would be called with flow-ref.

Upvotes: 2

Related Questions