我希望您能提供一个Spring Integration实现的流读取器。另一个应用程序(不是Java)将数据流(由美元符号分隔)发送到端口9999。此服务器监听。
现在,我想在Spring Integration框架中实现这个功能。我查看了https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server和http://docs.spring.io/autorepo/docs/spring-integration/2.0.0.M3/spring-integration-reference/html/stream.html。但是我不知道从哪里开始?连接到发送应用程序需要什么?(我真的很新于Spring Framework。)
对我来说困难在于术语。我应该创建TCP入站网关吗?还是接收通道适配器?或者因为我正在请求流,所以是出站??
在Gary的评论后编辑
首先,我通过使用telnet 127.0.0.1 9999
连接到它来确保流正在流动。
然后,我创建了一个简单的Java应用程序,并使用以下方法。目前这个方法可以工作。
public void readStream() throws IOException{
Scanner s = null;
try {
Socket skt = new Socket("localhost", 9999);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(
skt.getInputStream()));
s = new Scanner(bufferedReader);
s.useDelimiter("[$]");
System.out.println(s);
while (s.hasNext()) {
System.out.println("----------------------");
System.out.println(s.next());
}
} finally {
if (s != null) {
s.close();
}
}
}
现在,我想在Spring Integration框架中实现这个功能。我查看了https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server和http://docs.spring.io/autorepo/docs/spring-integration/2.0.0.M3/spring-integration-reference/html/stream.html。但是我不知道从哪里开始?连接到发送应用程序需要什么?(我真的很新于Spring Framework。)
对我来说困难在于术语。我应该创建TCP入站网关吗?还是接收通道适配器?或者因为我正在请求流,所以是出站??
在Gary的评论后编辑
<bean class="org.springframework.integration.ip.tcp.serializer.ByteArraySingleTerminatorSerializer" id="deserializer1">
<constructor-arg type="byte" value="$"/>
</bean>
<int-ip:tcp-connection-factory id="server" type="server" port="9999"
deserializer="deserializer1"
/>
<int-ip:tcp-inbound-channel-adapter id="adapter" connection-factory="server" request-channel="channel1"/>
<int:channel id="channel1" />