0
弹簧集成有一些问题。 比方说,有我的传出通信配置:弹簧集成tcp-connection-factory在回复之前关闭客户端连接
<int:channel id="outputChannel">
<int:queue />
</int:channel>
<int:channel id="outputChannel-in"> <!-- for response from server -->
<int:queue />
</int:channel>
<int-ip:tcp-connection-factory
id="outputSocket"
type="client"
single-use="true"
host="localhost"
port="666" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="outputChannel"
reply-channel="outputChannel-in"
connection-factory="outputSocket"
reply-timeout="20000" />
<int:gateway id="myGateway"
service-interface="some.package.SocketGateway"
default-request-channel="outputChannel"
default-reply-channel="outputChannel-in" />
<int:service-activator
id="myServiceActivator"
input-channel="outputChannel-in"
ref="myService"
method="incomingDataHandlingMethod" />
不管是什么,我会带接口some.package.SocketGateway做:
选项#1:
public interface SocketGateway{
byte[] send(String text);
}
选项#2:
public interface SocketGateway{
Future<byte[]> send(String text);
}
它没有收到任何消息。 我玩过很多配置。这只是我解决方案的一个版本,但他们都没有工作。
这里是一个服务器模拟:
ServerSocket someSocket = new ServerSocket(666);
Socket socket = someSocket.accept();
PrintWriter out =
new PrintWriter (socket.getOutputStream(), true);
BufferedReader in =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));
System.out.println("socket accepted");
String data = in.readLine();
while (data != null) {
System.out.println(data);
data = in.readLine();
}
System.out.println("data received");
out.println("ACK");
out.flush();
System.out.println("data sent");
socket.close();
someSocket.close();
当out.println("ACK");
的同时,连接关闭,不发送ACK后。当out.println("ACK");
在之前或之内时,它发送消息。
我该怎么做才能收到此消息?
编辑: 我也试过:
<int-ip:tcp-outbound-channel-adapter
id="outboundClient"
channel="outputChannel"
connection-factory="outputSocket" />
<int-ip:tcp-inbound-channel-adapter
id="outboundClient-in"
channel="outputChannel-in"
connection-factory="outputSocket" />
没有好的结果。
编辑: 我有这个客户端代码:
Socket echoSocket = new Socket("10.20.30.40", 11111);
PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
String encodedMessage = "someMessage";
String result = String.format("%c%s%c%c", (char) 11, encodedMessage, (char) 28, (char) 13);
out.println(result);
out.flush();
System.out.println("data sent");
File file = new File("result.txt");
BufferedWriter output = new BufferedWriter(new FileWriter(file));
String data;
while ((data = in.readLine()) != null) {
output.write(data);
}
output.flush();
output.close();
System.out.println("after while");
out.close();
in.close();
echoSocket.close();
这正常工作与外部服务器(服务器同步发送ACK消息,这是在字符串数据接收如何。使用Spring Integration实现这个结果我无法收到任何东西...
它不工作。如果我在一段时间或之前发送一些消息,它将被客户端套接字接收。当我调用发送接口时发送消息,等待20秒的回复,然后引发'org.springframework.integration.MessageTimeoutException:超时等待响应'。如果发送时,它会转到回复通道,然后调用service-activator方法。 – 2015-01-15 17:00:16
您的“服务器”逻辑有缺陷;我编辑了我的答案。 – 2015-01-15 17:34:49
的确如此。感谢您的回复。现在它可以工作。这只是一些模拟,另一方面是另一台服务器,但现在我知道我的配置是好的,他们将不得不解决这个问题,而不是我:) – 2015-01-15 17:48:17