我在以下screnario中使用SI 3.0.2:
客户端向我发送TCP套接字消息。
客户收到我的答复。
不幸的是,我依靠质量差的网络,有时在客户端和我的SI服务器之间断开连接。另一个方向(HTTP REST)是稳定的。因此,当SI服务器与REST服务通信时,我想检测客户端何时断开连接。
我找到了一个解决方案tcp-connection-event-inbound-channel-adapter我可以捕获TcpConnectionExceptionEvent,但不幸的是它不包含任何有关原始消息的信息或者我放在那里的任何头信息。 / p>
我该如何解决这个问题?
欢迎任何帮助!谢谢!
我的确切例外是:
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)
答案 0 :(得分:0)
目前,执行所需操作的唯一方法是向TcpConnection
添加拦截器并在send()
方法中捕获异常。
Documentation is here,但我刚注意到一个错误(在文档中);拦截器必须扩展TcpConnectionInterceptorSupport
并覆盖send()
方法......
try {
super.send(message);
}
catch (Exception e) {
...
}
编辑:
另一种方法是使用协作通道适配器而不是入站网关;这样,您可以在入站适配器上放置一个错误通道,当发送到出站适配器失败时,该错误通道将获得ErrorMessage
。下游流必须保留ip_connectionId
标题才能生效。