error handling when using splitter\aggregator in spring-integration

huangapple go评论69阅读模式
英文:

error handling when using splitter\aggregator in spring-integration

问题

我有以下的IntegrationFlow:

...
.split()
...
多个转换操作
...
.split()
...
多个转换操作
...
.aggregate()
.aggregate()

如何确保这两个聚合器(aggregator)会像通常一样运行(即使在中间消息转换过程中抛出异常,也要让这些聚合器认为上游处理已成功处理所有"split-messages")?注意:由于我有多个中间转换操作,我不能为每个转换都添加try/catch...一个潜在的想法可能是,将每个"multiple transformations here"包装成类似.gateway(subflow, c -> c.advice(myAdvice))的东西吗?
非常感谢您的专业知识。
最好的问候。

英文:

I have following IntegrationFlow:

...
.split()
...
multiple transformations here
...
split()
...
multiple transformations here
...
.aggregate()
.aggregate()

How can I guaranty that the two aggregators will behave as usual (i.e. make those aggregators believe that the upstream processing has been successful for all "split-messages") even if an exception is thrown in one of the intermediary message transformations ?
Note: as I have several intermediary transformations, I can't afford to add a try/catch to each and every of those transformations...one potential idea would be, maybe, to wrap each of my "...multiple transformations here..." into something like .gateway(subflow,c -> c.advice(myAdvice)) ?
Thanks a lot in advance for your expertise.
Best Regards

答案1

得分: 1

一个选项是使用ExpressionEvaluatingRequestHandlerAdvice,但正如您注意到的那样,您必须将其添加到splitaggregate之间的每个步骤中:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#expression-advice。

另一个选项,正如您指出的,是为这些处理步骤使用gateway(),并使用一个单一的错误处理程序。是的,相同的ExpressionEvaluatingRequestHandlerAdvice可以在提到的advice()中使用,这样从GatewayMessageHandler(本质上是subflow)抛出的任何异常都将由一个try..catch处理。

您需要确保复制失败的消息头以满足聚合器对关联的期望。

另一种方法是在GatewayEndpointSpec上使用errorChannel()来进行try..catch逻辑,但我猜这与我们可以使用ExpressionEvaluatingRequestHandlerAdvice做的事情类似。

英文:

On of the option is to use an ExpressionEvaluatingRequestHandlerAdvice, but as you noticed then you have to add into every single step between split and aggregate: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#expression-advice.

Another option as you pointed out would be a gateway() for those processing steps with a single error handler. And yes: same ExpressionEvaluatingRequestHandlerAdvice could be used in the mentioned advice() this way any exception thrown from a GatewayMessageHandler (essentially subflow) would be handled by only one try..catch.

You would need to ensure to copy a failed message headers to fulfill an aggregator expectations for correlation.

Another way is to use an errorChannel() on that GatewayEndpointSpec for a try..catch logic, but I guess it would be similar to what we can do with the ExpressionEvaluatingRequestHandlerAdvice.

huangapple
  • 本文由 发表于 2023年7月20日 18:12:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定