【发布时间】:2015-06-08 15:26:15
【问题描述】:
我已经创建了一个简单的带有 spring 集成的 tcp 服务器,它使连接保持活动状态并在连接期间响应每个请求。
在那个 requestMethod 中,我还可以读取 MessageHeder 来获取 connectionId。
现在我想从服务器向客户端发送消息。
据我了解,我需要将 connectionid 放在 MessageHeader 中,然后发送消息。但我不知道如何做后一个。我已准备好消息,但如何发送/推出?
这是我的 xml 配置:
<bean id="lfSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer"/>
<int-ip:tcp-connection-factory
id="socketserver"
type="server"
port="30124"
using-nio="true"
deserializer="lfSerializer"
serializer="lfSerializer"
single-use="false"/>
<int-ip:tcp-inbound-channel-adapter id="inboundServer"
channel="inputChannel"
connection-factory="socketserver"/>
<int-ip:tcp-outbound-channel-adapter id="outboundServer"
channel="outputChannel"
connection-factory="socketserver"
/>
<int:channel id="inputChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:channel id="outputChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:logging-channel-adapter id="logger" level="DEBUG" log-full-message="true"/>
<int:service-activator input-channel="inputChannel"
output-channel="outputChannel"
ref="echoService"
method="test"/>
<bean id="echoService"
class="com.examples.EchoService" />
我还尝试创建一个 bean 和另一个 serviceactivator 用于输出,然后自动装配该 bean 并将其称为“发送”方法,但我不知道在该发送方法中实现什么来发送消息。
【问题讨论】:
标签: java tcp spring-integration