【发布时间】:2017-03-13 14:11:59
【问题描述】:
对 spring 和 spring 集成还是新手,所以请多多包涵。 =)
我已经设置了一个客户端以使用 TCP 连接到远程服务器。一旦建立连接,服务器就会发送一条消息。使用 ngrep 我已验证连接已建立并且消息是从服务器发送的。
通过使用网关接口“gw”,我可以成功接收到消息。但是我想做的是在收到消息时触发 com.example.Client.onMessage 方法。我的理解是,这应该可以使用如下所示的 ServiceActivator 来实现。这是真的还是我必须使用自己的专用线程进行阻塞接收?谢谢。
配置
<bean id="javaDeserializer"
class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer" />
<int-ip:tcp-connection-factory id="client"
type="client" host="localhost" port="12000"
single-use="false" so-timeout="10000" so-keep-alive="true" deserializer="javaDeserializer"
serializer="javaSerializer"/>
<int:gateway id="gw" service-interface="com.example.Interface"
default-request-channel="input" default-reply-channel="replies" />
<int:channel id="input" />
<int:channel id="replies">
<int:queue />
</int:channel>
<int-ip:tcp-outbound-channel-adapter
id="outboundClient" channel="input" connection-factory="client" />
<int-ip:tcp-inbound-channel-adapter
id="inboundClient" channel="replies" connection-factory="client"
client-mode="true" retry-interval="10000" auto-startup="true" />
<int:service-activator input-channel="input" output-channel="replies" ref="com.example.Client" method="onMessage" />
ServiceActivator
@EnableIntegration
@IntegrationComponentScan
@MessageEndpoint
public class Client {
@ServiceActivator
public void onMessage(byte[] received) {
//Not called
}
}
【问题讨论】:
标签: java spring spring-integration