弹簧整合抛出异常与相关标识 [英] spring integration throw exception with correlation id

查看:148
本文介绍了弹簧整合抛出异常与相关标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用弹簧集成处理批处理时我遇到问题。
通常在分解器之后,所有元素(消息)将被分配一个相关符号以供将来在聚合器中进行分组,但问题是当处理元素(消息)时抛出异常时,将创建一个MeesageException并且correlation_id丢失。



我可以使用HeaderEnricher来添加correlation_id,但是它不能被硬编码我假设,如果有多个请求聚集在一起,事情会被组合在一起,一切都会被搞砸了
根本原因是当抛出异常弹簧集成不会附加correlation_id ...并且似乎永远不会被重新获得...



聚合器会抱怨关于CorrelationStrategy失败



如何处理?
假设我的期望可能是批量的10个数据点,我想给{fail 5,pass 5}或sth

解决方案

当Spring Integration组件抛出 org.springframework.messaging.MessagingException 时,它通常包含一个 failedMessage 属性表示一个 requestMessage 导致了这个问题。



您所需的所有标题 correlationId sequenceNumber sequenceSize 等)正好在那个财产。



如果要将错误处理结果发送回聚合器,您应该从 failedMessage 到新创建的消息。



默认情况下,框架不会执行此操作,因为 ErrorMessage 是完全独立的流和不能保证它总是回到主要流程,例如用于聚合。



查看错误处理章节


I have a problem with handling batch processing with spring integration. Normally After splitter, all the element(Message) will be assigned with a correlation_id for future grouping in Aggregator, but the problem is that when there is a exception thrown when processing the element(Message), a MeesageException will be created and the correlation_id is lost.

I can use HeaderEnricher to add the correlation_id but it cannot be hard coded I assume, other wise if there are multiple requests come together, things gonna be grouped together and everything will be messed up. The root cause is when throwing exception spring integration will not attach the correlation_id... and it seems never be re-gained...

Aggregator will complain about "CorrelationStrategy is failing"

How to deal with this? Let's say my expectation could be 10 datapoint in batch, and I want to give response for {failed 5, pass 5} or sth

解决方案

When a org.springframework.messaging.MessagingException is thrown by the Spring Integration components, it is typically contains a failedMessage property to indicate a requestMessage which caused the problem.

All the required headers for you (correlationId, sequenceNumber, sequenceSize etc.) are exactly in that property.

If you are going to send the error-handling result back to the aggregator you should copy headers from that failedMessage to newly created message.

The Framework doesn't do that by default because a ErrorMessage is fully separate flow and there is no guaranty that it always comes back to the main flow, e.g. for aggregation.

See more information in the Error Handling chapter.

这篇关于弹簧整合抛出异常与相关标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆