首页 > 解决方案 > Spring 集成 - 重试在异常情况下建立连接

问题描述

我的应用程序使用 spring 集成与第三方系统通信。我发送了一个有效负载,我得到了我解析和使用的响应。都好。请在我使用的 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>

标签: springspring-integration

解决方案


您可以添加一个retry-advice到您的<int-ip:tcp-outbound-gateway>

<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


推荐阅读