【发布时间】:2017-05-08 04:58:24
【问题描述】:
我无法清楚地理解如何在 Spring Integration 中读取 TCP 流。我有一个外部服务,它向连接到它的客户端(TCP、Java 套接字)广播一些数据。我已经在 Spring Integration 中尝试了许多配置。我的应用程序成功连接到我的外部服务(我可以从服务的日志中确认),但我仍然无法捕获流。但是,当我手动将一些消息发送到服务(通过 MessageChannel)时,我的 bean 工作正常。这确实意味着我的配置配置为捕获写入事件。我找不到明确的指南或手册来配置它以接收 TCP 流。我的项目中有这个 xml 配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="accumulator"
class="ru.utilex.trueguard.Accumulator" />
<int-ip:tcp-connection-factory id="client"
type="client"
host="192.168.2.28"
port="8383"
so-timeout="10000"/>
<int:channel id="input" />
<int:channel id="toSA" />
<int-ip:tcp-outbound-channel-adapter id="inboundClient"
client-mode="true"
channel="input"
auto-startup="true"
connection-factory="client"/>
<int:object-to-string-transformer id="serverBytes2String"
input-channel="input"
output-channel="toSA"/>
<int:service-activator
input-channel="toSA"
ref="accumulator"
method="read"/>
</beans>
我的累加器类应该是我的接收通道的端点:
public class Accumulator {
public void read(String buffer) {
System.out.println("We have caught this message: " + buffer);
}
}
【问题讨论】:
标签: java spring sockets tcp spring-integration