我已經創建了一個簡單的tcp服務器與彈簧集成,它保持連接活着並在連接期間響應每個請求。有彈簧集成tcpserver來管理客戶端併發送消息
在該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,並呼籲它「送」的方法,但我不知道是什麼在該發送方法中實現發送消息。
自動裝配頻道是我錯過的。謝謝。 :) – Jens