0

我正在使用 spring 集成 XML,并且想知道处理错误处理的最佳方法是什么。

我正在使用 s3 连接到 s3 s3-inbound-streaming-channel-adapter,然后从 s3 存储桶转换 csv 文件。

可能发生的潜在错误是:

  1. 如果文件中的一行无效,则可能会发生转换异常,因此可能会引发自定义错误:

LineTransformationException

  1. 如果在 s3 存储桶上错误地放置了图像文件并再次出现转换异常怎么办

  2. s3 可能会关闭并且可能会得到

原因:com.amazonaws.SdkClientException:无法执行 HTTP 请求:连接到 localhost:4572 [localhost/127.0.0.1] 失败:连接被拒绝

许多已知和未知错误的列表可以继续......

  1. 那么处理所有这些错误的最佳方法是什么?通过自定义ErrorHandlerexception-type-router

  2. 如果做到这一点,ErrorHandler那么如何满足这么多的例外。

  3. 是否有一个包罗万象的异常处理程序?

    公共类错误处理程序{

    公共无效句柄失败(消息错误消息){

    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"/>
4

1 回答 1

1

s3-inbound-streaming-channel-adapter与它一起可以<poller>error-channel. 默认情况下,轮询错误(以及所有下游)被路由到全局errorChannelhttps ://docs.spring.io/spring-integration/docs/5.0.5.RELEASE/reference/html/configuration.html#namespace-错误处理程序

于 2018-06-08T14:49:59.283 回答