我正在使用 spring 集成 XML,并且想知道处理错误处理的最佳方法是什么。
我正在使用 s3 连接到 s3 s3-inbound-streaming-channel-adapter
,然后从 s3 存储桶转换 csv 文件。
可能发生的潜在错误是:
- 如果文件中的一行无效,则可能会发生转换异常,因此可能会引发自定义错误:
LineTransformationException
如果在 s3 存储桶上错误地放置了图像文件并再次出现转换异常怎么办
s3 可能会关闭并且可能会得到
原因:com.amazonaws.SdkClientException:无法执行 HTTP 请求:连接到 localhost:4572 [localhost/127.0.0.1] 失败:连接被拒绝
许多已知和未知错误的列表可以继续......
那么处理所有这些错误的最佳方法是什么?通过自定义
ErrorHandler
或exception-type-router
如果做到这一点,
ErrorHandler
那么如何满足这么多的例外。是否有一个包罗万象的异常处理程序?
公共类错误处理程序{
公共无效句柄失败(消息错误消息){
MessagingException payload = (MessagingException) errorMmessage.getPayload(); LOG.info(">>--- Exception --- " + payload.getCause());
}}
或者
<int:exception-type-router input-channel="errorChannel"
default-output-channel="nullChannel">
<int:mapping exception-type="com.api.exception.TransformationException"
channel="transformErrorChannel"/>
<int:mapping exception-type="com.amazonaws.SdkClientException"
channel="clientErrorChannel"/>
</int:exception-type-router>
<int:channel id="transformErrorChannel"/>
<int:service-activator ref="errorHandler"
method="handleFailure"
input-channel="transformErrorChannel"
output-channel="nullChannel"/>
<int:service-activator ref="clientErrorHandler"
method="handleFailure"
input-channel="clientErrorChannel"
output-channel="nullChannel"/>