【发布时间】:2020-10-11 18:47:30
【问题描述】:
我需要一些关于迁移到 Spring Integration 的帮助。 实际上,我们有一个基于 java.net 包的组件,它只包含几个带有 java 经典 TCP 客户端的类,没什么花哨的,它实际上可以通过 tcp 向旧服务器发送一些请求。这是发送和接收消息的代码:
public String sendMessage(String info) {
try {
PrintStream ps = new PrintStream(clientSocket.getOutputStream());
ps.println(info);
InputStreamReader ir = new InputStreamReader(clientSocket.getInputStream());
BufferedReader br = new BufferedReader(ir);
return br.readLine();
} catch (IOException e) {
log.debug(e.getMessage());
}
return "";
}
问题是我想在客户端开始使用Spring Integration,但是我无法更改服务器,因为它属于另一家公司,但是我没有收到服务器的响应,我尝试了很多配置而且一点运气都没有。 这是我现在的客户端配置:
<int:gateway id="gw"
service-interface="pe.financieraoh.core.cointegrador.tcp.SimpleGateway"
default-request-channel="input"/>
<int-ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="7777"
single-use="false"
serializer="connectionSerializeDeserialize"
deserializer="connectionSerializeDeserialize"
/>
<int:channel id="input" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000" />
<bean id="connectionSerializeDeserialize"
class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer"/>
<int:object-to-string-transformer id="clientBytes2String"
input-channel="clientBytes2StringChannel" />
我尝试了很多并且总是收到 TimeOutConnection 异常,我很确定服务器没有收到我的请求,但我不能确定,因为我无权访问服务器日志。我唯一的指南是客户端中的旧代码可以正常工作。 感谢您的帮助。
这是来自服务器的日志,我尝试了几种反序列化器,结果相同,2020-06-21 23:47:10.377 ERROR 1 --- [nio-8080-exec-7] osiip .tcp.TcpOutboundGateway:Tcp 网关异常 org.springframework.integration.MessageTimeoutException:在 org.springframework.integration.ip.tcp.TcpOutboundGateway.getReply 等待响应超时(TcpOutboundGateway.java:243)~[spring-integration-ip- 5.3.0.RELEASE.jar:5.3.0.RELEASE]
【问题讨论】:
-
请用日志更新问题,而不是在 cmets 中发布。
标签: spring tcp spring-integration tcpclient