【问题标题】:Spring Integration error-channel doesn't receive all exceptionsSpring Integration 错误通道未收到所有异常
【发布时间】:2017-06-07 09:45:19
【问题描述】:

我正在使用 spring 集成的错误通道来捕获框架中的异常。但是在两个相同类型的通道中,一个抛出的异常被错误处理程序接收,而另一个则没有。

    
<int:gateway id="myGateway" service-interface="com.si.MyGateway" request-
channel="myRequestChannel" error-channel="errorHandlingChannel">
<!-- Redirects exceptions to error-channel -->            
<int:chain input-channel="myRequestChannel" output-channel="lastChannel">
            <int:header-enricher>
                <int:error-channel ref="errorHandlingChannel">
            <int:header-enricher>
            <int:service-activator ref="testActivator1" 
method="generateException" requires-reply="true" />
            </int:chain>
<!-- Does not redirect exceptions to error-channel -->
                <int:chain input-channel="lastChannel" output-
channel="nullChannel">
            <int:header-enricher>
                <int:error-channel ref="errorHandlingChannel">
            <int:header-enricher>
            <int:service-activator ref="testActivator2" 
method="generateException" requires-reply="true" />
<int:filter ref="myFilter" discard-channel="nullChannel" />
            <int:service-activator ref="testActivator3" 
method="generateException" requires-reply="true" />
<int:filter ref="myFilter" discard-channel="nullChannel" />
            </int:chain>
    <int:service-activator input-channel="errorHandlingChannel" 
ref="errorHandler" method="handle" />

        

errorHandler 的handle 方法接受MessagingException。当我从 myRequestChannel 抛出异常时,errorHandler 会接收到它,但是当从 testActivator2 或 testActivator3 抛出相同的异常时,它根本不会到达 errorHandler。

两个通道都定义为异步通道:

<int:channel>
<int:queue capacity="10">
</int:channel>

在调试时,我发现所有方法的异常都被抛出,并且当内部类最终抛出 MessagingException 时,所有方法的异常都被抛出并通过 spring 的类,但最后两个激活器的异常没有到达处理程序。

可能是什么原因?

【问题讨论】:

  • 谢谢,但我所有的频道都是异步的,所以链接中提到的解决方案已经实现但无济于事。
  • 您不需要header-enrichers - 网关会自动设置errorChannel 标头。您的配置中没有什么明显的;我建议您为org.springframework.integration 启用调试日志记录;如果您无法从日志中找出答案,请使用日志编辑您的问题。
  • @GaryRussell 谢谢。我通过在服务激活器之后添加过滤器来编辑我的问题。早些时候,我遇到了这个问题,因为我的错误通道配置错误导致静默失败。在我纠正了这个问题之后,我意识到对于许多链来说,错误仍然没有被抛出到错误通道。来自服务激活器的异常首先进入过滤器,该过滤器拒绝了异常消息,因为逻辑拒绝了所有非特定类型的消息。我仍然不确定为什么异常没有直接进入错误通道。

标签: java spring error-handling spring-integration


【解决方案1】:

你会抛出什么样的异常?

如果是MessagingException,则必须与failedMessage一起提供,否则错误将发送到&lt;poller&gt;上的默认errorChannel

【讨论】:

  • 谢谢。我通过在服务激活器之后添加过滤器来编辑我的问题。早些时候,我遇到了这个问题,因为我的错误通道配置错误导致静默失败。在我纠正了这个问题之后,我意识到对于许多链来说,错误仍然没有被抛出到错误通道。来自服务激活器的异常首先进入过滤器,该过滤器拒绝了异常消息,因为逻辑拒绝了所有非特定类型的消息。我仍然不确定为什么异常没有直接进入错误通道。
猜你喜欢
  • 2014-03-03
  • 2015-05-18
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 2016-02-22
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多