我使用的春天開機即按照TcpInboundGateway的例子,所以不同的設備發送數據到這個網關,事情工作正常,但兩者之間在其記錄顯示以下異常:導致SocketException Spring集成TcpInboundGateway讀異常:連接復位
2015-12-29 18:42:19.455 ERROR 3465 --- [ool-3-thread-47] o.s.i.i.tcp.connection.TcpNetConnection : Read exception 106.221.159.216:38170:8765:934c050d-c4b5-4466-98ab-ee87714c3d00 SocketException:Connection reset
如果這個異常重置連接,那麼如何避免這種重置?這個錯誤的原因是什麼?
我的代碼如下
@SpringBootApplication
@IntegrationComponentScan
public class SpringIntegrationApplication extends SpringBootServletInitializer{
public static void main(String[] args) throws IOException {
ConfigurableApplicationContext ctx = SpringApplication.run(SpringIntegrationApplication.class, args);
System.in.read();
ctx.close();
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringIntegrationApplication.class);
}
private static Class<SpringIntegrationApplication> applicationClass = SpringIntegrationApplication.class;
@Bean
TcpNetServerConnectionFactory cf(){
TcpNetServerConnectionFactory connectionFactory=new TcpNetServerConnectionFactory(8765);
return connectionFactory;
}
@Bean
TcpInboundGateway tcpGate(){
TcpInboundGateway gateway=new TcpInboundGateway();
gateway.setConnectionFactory(cf());
gateway.setRequestChannel(requestChannel());
return gateway;
}
@Bean
public MessageChannel requestChannel(){
return new DirectChannel();
}
@MessageEndpoint
public class Echo {
@ServiceActivator(inputChannel="requestChannel")
public byte[] echo(byte[] in,@SuppressWarnings("deprecation") @Header("ip_address") String ip){
byte[] rawbytes = gosDataSerivce.byteArrayToHex(in,ip);//Process bytes and returns result
return rawbytes;
}
}
}
設置singleUse
到true
現在異常消息略有改變後。
2015-12-31 06:09:00.481 ERROR 16450 --- [ool-3-thread-10] o.s.i.i.tcp.connection.TcpNetConnection : Read exception 106.221.146.40:9195:8765:1b4755e8-5b0c-44b9-b4e6-b3aacc25e228 SocketException:Connection reset
使用案例: 我有一個建立GPRS連接TcpInboundGateWay
,併發送登錄數據包幾個客戶,packet.If客戶端收到服務器答覆登錄數據包,然後將數據發送我們的服務器會回覆此登錄數據包定期間隔。服務器需要回答這些數據包也,如果服務器無法發送答覆這些數據包,然後客戶端GPRS連接終止和客戶端將嘗試建立連接again.Let我知道,如果這種使用情況下可與處理TcpInboundGateWay
網絡跟蹤分析 客戶端和服務器之間的通信的一般流程如下:客戶端發送登錄數據包從ip
說106.221.148.165
因此在命名106.221.148.165:63430:8765:cc105da2-dae4-494b-af9c-d1ba268f34f1
創建服務器連接,客戶端從ip
only.So一切發送後續報文正常,但經過一段時間後,相同的客戶端從另一個ip
發送其登錄數據包,例如106.221.142.204
。並且隨後的數據包m新ip
。但在日誌中出現以下錯誤,表示之前發生連接異常。
2016-01-05 05:16:14.871 ERROR 6819 --- [pool-3-thread-5] o.s.i.i.tcp.connection.TcpNetConnection : Read exception 106.221.148.165:63430:8765:cc105da2-dae4-494b-af9c-d1ba268f34f1 SocketException:Connection reset
我已經設置singleUse
true
,我使用spring integration 4.2.1
我正在使用Spring Integration 4.2.1,並將singleUse設置爲true後,異常消息稍有變化。添加問題以及我的用例 – MasterCode
我沒有看到上述兩個錯誤消息之間的區別。你的用例很好。如果你在4.2.x中看到這個異常(不管是否一次性使用),重置意味着客戶端正在關閉(中止)套接字。您可能需要查看網絡跟蹤和/或客戶端代碼以查看原因。 [這是對有序VS的描述。中止套接字關閉](https://docs.oracle.com/javase/8/docs/technotes/guides/net/articles/connection_release.html)。默認的序列化程序會將CRLF附加到消息中,也許客戶端不喜歡那樣? (默認的反序列化程序也期望CRLF)。 –
網絡分析結果在編輯 – MasterCode