【问题标题】:Spring Integration: Listening for exceptions on inbound-gatewaySpring Integration:在入站网关上监听异常
【发布时间】:2013-03-26 04:17:54
【问题描述】:

我是 Spring 集成的新手,所以我可能会误用术语。 我有一个 ws:inbound-gateway 监听肥皂网络服务请求。

<int-ws:inbound-gateway id="myInGW"
                        request-channel="headersMapPopulationChannel"
                        reply-channel="ws-response-channel"
                        marshaller="marshaller"
                        unmarshaller="marshaller"/>

它将传入请求发送到 headersMapPopulationChannel 并将消息发送到适配器(用于从 JAXB 类转换为域),然后拆分器将其拆分为验证、日志记录和持久性。坚持不懈后,我正在根据请求运行与业务相关的事情。我想对所有这些都有异常控制点,这样我就可以管理在异常情况下要做什么。我故意在业务类中放了一个 throw 异常语句。抛出异常,但我的频道似乎没有得到它。 配置:

<int-ws:inbound-gateway id="myInGW"
                        request-channel="headersMapPopulationChannel"
                        reply-channel="ws-response-channel"
                        error-channel="ws-error-channel"
                        marshaller="marshaller"
                        unmarshaller="marshaller"/>

<int:channel id="ws-error-channel"/>

<int:service-activator input-channel="ws-error-channel"
                       expression="@exceptionHandlerService.handleThrowable(payload)"/>
<bean id="exceptionHandlerService" class="pack.integration.service.ExceptionHandlerService"/>

我也不知道在我的最外面的频道中控制异常是否正确。我应该在转发消息的任何地方监听异常吗?

【问题讨论】:

    标签: exception-handling integration spring-integration channel


    【解决方案1】:

    这是处理异常的正确方法。

    异常将被包装在MessagingException 中,并作为ErrorMessage 的有效负载发送到error-channelMessagingException 有两个属性cause(原始异常)和failedMessage(导致异常的消息)。

    如果要向客户端返回 SOAP 错误,错误通道流必须抛出异常。

    如果您没有在频道上看到ErrorMessage,则肯定是其他东西捕获了异常。

    我建议你打开调试日志并通过系统跟踪消息。

    【讨论】:

    • 我已经按照你所说的追踪了流程,我注意到了一个 'ignore-send-failures="true"' 声明。删除它使错误通道能够捕获异常。感谢您的回复。
    【解决方案2】:

    我还使用分段网关将所有异常重定向到另一个消息流,并从那里决定如何处理它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-07
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      相关资源
      最近更新 更多