Spring 集成 - 在异常情况下重试建立连接 [英] Spring integration - Retry to establish connection on exception scenarios
问题描述
我的应用程序使用 spring 集成与第三方系统进行通信.我发送一个有效负载,我得到一个我解析和使用的响应.都很好.请在下面找到我使用的 SI xml.
My application communicates to a third party system using spring integration. I send a payload for which I get a response that I parse and use. All good. Please find below the SI xml that I use.
现在我想应用程序重试在我尝试连接的服务器不可用或超时或拒绝连接等异常情况下建立连接.如何使用 SI xml 配置实现此目的?请指导.
Now I want to application retry to establish connection on exception scenarios where the server I'm trying to connect isn't available or on time outs or if it refuses to connect etc. How can I achieve this using SI xml configuration? Please guide.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<int:gateway id="gw" service-interface=" com.RxGateway"
default-request-channel="objectOut" />
<int:channel id="objectOut" />
<int-ip:tcp-connection-factory id="client"
type="client" host="10.236.249.xx" port="9103" single-use="false"
so-timeout="50000000" using-nio="false" so-keep-alive="true"
serializer="customDSerializer" deserializer="customDSerializer" />
<bean id="customDSerializer" class="com.CustomSerializerDeserializer">
<property name="maxMessageSize" value="4096" />
</bean>
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="objectOut" reply-channel="toSA" connection-factory="client"
request-timeout="100000" reply-timeout="50000"/>
<int:service-activator input-channel="toSA"
ref="rxService" method="parseResponse"/>
<bean id="rxService" class="com.RxService"/>
<int:channel id="toSA" />
<int:channel id="bytesIn" />
</beans>
推荐答案
您可以在retry-advice
代码>:
<int-ip:tcp-outbound-gateway>
<int-ip:request-handler-advice-chain>
<int:retry-advice/>
</int-ip:request-handler-advice-chain>
</int-ip:tcp-outbound-gateway>
在参考手册中查看更多信息:https://docs.spring.io/spring-integration/docs/current/reference/html/#message-handler-advice-chain
See more info in the Reference Manual: https://docs.spring.io/spring-integration/docs/current/reference/html/#message-handler-advice-chain
这篇关于Spring 集成 - 在异常情况下重试建立连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!