【问题标题】:spring integration error handling different typesspring 集成错误处理不同类型
【发布时间】:2018-06-08 14:44:56
【问题描述】:

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

我正在使用s3-inbound-streaming-channel-adapter 连接到 s3,然后从 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. 还有一个包罗万象的异常处理程序吗?

    公共类 ErrorHandler {

    public void handleFailure(Message errorMmessage) {

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

【问题讨论】:

    标签: spring spring-integration spring-integration-aws


    【解决方案1】:

    s3-inbound-streaming-channel-adapter 及其&lt;poller&gt; 可以与error-channel 一起配置。默认情况下,轮询错误(以及所有下游)被路由到全局errorChannelhttps://docs.spring.io/spring-integration/docs/5.0.5.RELEASE/reference/html/configuration.html#namespace-errorhandler

    【讨论】:

    • 谢谢。我已经使用了自定义错误处理程序,其中有两种方法来处理转换异常,例如messageHandlingFailure(Message message) 和另一个用于处理任何其他类型的错误,例如处理失败(消息 消息)。你认为这是正确的做法吗?
    • 另外如何禁用 LoggingHandler?因为它不断输出阶段跟踪。
    • 你可以声明你拥有errorChannel bean。这样LoggingHandler 将被禁用。
    猜你喜欢
    • 1970-01-01
    • 2015-05-24
    • 2018-07-05
    • 2015-10-03
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多