【发布时间】:2017-12-10 19:23:42
【问题描述】:
我有三个不同的系统。我正在使用 Spring 集成来同步所有这些系统中的数据。
系统 1 调用 ---> 系统 2 通过 http:inbound gateway
<int-http:inbound-gateway id="gateway"
path="/save" supported-methods="POST, PUT"
request-channel="requestChannel" reply-channel="replyChannel"
request-payload-type="com.model.Request"
mapped-request-headers="source" error-channel="errorChannel" />
系统2将调用服务方法来持久化数据,如果请求有效则返回响应,否则抛出异常
<int:service-activator ref="serviceMethod"
method="saveIfValid" input-channel="requestChannel"
output-channel="serviceOutput" />
<int:recipient-list-router id="id1"
input-channel="serviceOutput">
<int:recipient channel="system1" />
<int:recipient channel="system3" />
</int:recipient-list-router>
只有在操作成功的情况下,我才需要向系统 1 和系统 3 发送服务方法响应。 调用服务方法后,根据服务方法响应,使用transformer生成对系统3的请求。在转换器之后,我将请求放入 mq 队列中。
<int:transformer id="transformer1"
method="convert" input-channel="system3"
output-channel="jmsInput">
<bean
class="com.transformer.System3Transformer" />
</int:transformer>
<int-jms:outbound-channel-adapter id="adapter"
channel="jmsInput" destination-name="queueName">
</int-jms:outbound-channel-adapter>
更新的 JMS 出站代码
<int-jms:outbound-channel-adapter id="jms1"
channel="jmsIn" destination-name="queueName">
<int-jms:request-handler-advice-chain>
<bean
class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="T(Boolean).TRUE" />
<property name="successChannelName" value="afterSuccessDeleteChannel" />
<property name="onFailureExpression" value="T(Boolean).FALSE" />
<property name="failureChannelName" value="afterFailRenameChannel" />
</bean>
</int-jms:request-handler-advice-chain>
</int-jms:outbound-channel-adapter>
我的问题是
- 如果服务类失败,我需要发送错误响应并停止流程
- 如果服务方法成功持久化数据,但转换失败,系统 1 应获得成功响应并记录错误。
- 由于我在出站适配器中使用错误通道,即使变压器发生错误,它也会返回到系统 1。
- 请建议我如何在不使用全局错误通道的情况下处理错误以及如何处理 jms 出站适配器中的错误。
- 感谢您回答我的问题
【问题讨论】:
标签: error-handling spring-integration