春季集成 - 重试以在例外情况下建立连接



我的应用程序使用春季集成通信到第三方系统。我发送有效载荷,我会得到我分析和使用的响应。都好。请在我使用的SI XML下面找到。

现在,我想将应用程序重试以在我试图连接的服务器不可用的服务器或准时出局或拒绝连接的情况下建立连接。如何使用SI XML配置来实现这一目标?请指导。

<?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>

您可以在<int-ip:tcp-outbound-gateway>中添加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/referent/referent/html/#message handler-advice-chain

相关内容

最新更新