spring - 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>
解决方案
您可以添加一个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
推荐阅读
- ios - Here Maps 环形交叉路口图标
- .net - .NET 调用 Web 服务在定义为 int 的字段中返回 null
- android - 如何获取 Frame().camera ARCore
- sql-server - 计算分组结果
- asp.net-mvc - 为什么我的剃须刀@if 评估不正确?
- dart - 如何设计像这样带有标题和 boxTextField 的 dropDownButton?
- reactjs - 我有一个 addEvent 函数,但没有将正确的状态传递给它
- spring - spring cloud stream kafka的默认Ack模式是什么?
- python - Keras 和 OpenCV (CV2) 作为 Python 可执行文件的依赖项?
- docker - kafka_connect 没有找到它的连接器