Spring integration TcpInboundGateway ReplyChannel错误处理
我在以下脚本中使用SI 3.0.2: 客户端向我发送TCP套接字消息Spring integration TcpInboundGateway ReplyChannel错误处理,spring-integration,Spring Integration,我在以下脚本中使用SI 3.0.2: 客户端向我发送TCP套接字消息 使用TCPInboundGateway接收消息 使用HttpOutboundGateway转换消息并发送到REST服务 接收HTTP响应并再次转换它 通过TCPInboundGateway replyChannel将转换后的消息发送回客户端 客户收到了我的答复 不幸的是,我依赖的是一个质量差的网络,有时会断开客户端和我的SI服务器之间的连接。另一个方向(HTTP REST)是稳定的。因此,我希望在SI服务器与REST服务通信时
01 júl. 2014 16:51:35,504 ERROR pool-1-thread-2 org.springframework.integration.ip.tcp.TcpInboundGateway:118 - Failed to send reply
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:141)
at org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer.serialize(ByteArrayCrLfSerializer.java:79)
at org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer.serialize(ByteArrayCrLfSerializer.java:31)
at org.springframework.integration.ip.tcp.connection.TcpNetConnection.send(TcpNetConnection.java:99)
at org.springframework.integration.ip.tcp.TcpInboundGateway.doOnMessage(TcpInboundGateway.java:116)
at org.springframework.integration.ip.tcp.TcpInboundGateway.onMessage(TcpInboundGateway.java:89)
at org.springframework.integration.ip.tcp.connection.TcpNetConnection.run(TcpNetConnection.java:169)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
目前,您想要做的唯一方法是向
TcpConnection
添加拦截器,并在send()
方法中捕获异常
,但我只是注意到一个bug(在文档中);拦截器必须扩展TcpConnectionInterceptorSupport
,只需覆盖send()
方法
try {
super.send(message);
}
catch (Exception e) {
...
}
编辑:
另一种选择是使用协作通道适配器,而不是入站网关;这样,您可以在入站适配器上设置一个错误通道,当发送到出站适配器失败时,该通道将获得一条
ErrorMessage
。下游流必须保留ip\U连接ID
标头,才能正常工作。添加了另一个备选方案。感谢您的建议。我选择了第二个选项,效果非常好!