我有三個不同的系統。我正在使用Spring集成來同步所有這些系統中的數據。彈簧集成中的錯誤處理
系統1通話--->系統2通過http:入站網關
<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發送服務方法響應。 調用服務方法後,根據服務方法響應,使用變壓器生成系統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"
\t \t channel="jmsIn" destination-name="queueName">
\t \t <int-jms:request-handler-advice-chain>
\t \t \t <bean
\t \t \t \t class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
\t \t \t \t <property name="onSuccessExpression" value="T(Boolean).TRUE" />
\t \t \t \t <property name="successChannelName" value="afterSuccessDeleteChannel" />
\t \t \t <property name="onFailureExpression" value="T(Boolean).FALSE" />
\t \t \t \t <property name="failureChannelName" value="afterFailRenameChannel" />
\t \t \t </bean>
\t \t </int-jms:request-handler-advice-chain>
\t </int-jms:outbound-channel-adapter>
我的問題是
- 如果服務類失敗我需要發送錯誤響應,並停止了流動
- 一世f服務方法成功保存數據,但轉換失敗,系統1應該獲得成功響應並記錄錯誤。
- 在這裏,因爲我在出站適配器中使用錯誤通道,即使變壓器出現錯誤,它也會返回到系統1.
- 請建議如何處理錯誤而不使用全局錯誤通道以及如何處理出站jms中的錯誤適配器。
- 感謝你回答我的quesion
謝謝你回答我的問題。如果在中發生任何錯誤,我只是想將它記錄下來,我不想向系統1顯示錯誤。你能否幫助實現這一點? –
' \t \t \t \t <屬性名=」 onSuccessExpression」值= 「有效載荷」/> \t \t \t \t <屬性名= 「successChannelName」 值= 「afterSuccessDeleteChannel」/> \t \t \t \t <屬性名= 「onFailureExpression」 值= 「有效載荷」/> \t \t \t \t <屬性名= 「failureChannelName」 值= 「afterFailRenameChannel」/> \t \t \t ' –
請參閱上面的代碼。它既涉及成功渠道,也涉及失敗渠道。你能解釋一下它是如何評估它是成功還是失敗? 。 –