Java 收到消息时的spring集成回调
spring和spring集成仍然是新手,请耐心听我说。=) 我已经设置了一个客户端,使用TCP连接到远程服务器。一旦建立连接,服务器就会发送消息。使用ngrep,我已经验证了连接已启动,并且消息已从服务器发送 通过使用网关接口“gw”,我可以成功接收消息。然而,我想做的是在收到消息时触发com.example.Client.onMessage方法。我的理解是,这应该可以使用如下所示的ServiceActivator。这是真的还是我必须使用自己的专用线程来执行阻塞接收?谢谢 配置Java 收到消息时的spring集成回调,java,spring,spring-integration,Java,Spring,Spring Integration,spring和spring集成仍然是新手,请耐心听我说。=) 我已经设置了一个客户端,使用TCP连接到远程服务器。一旦建立连接,服务器就会发送消息。使用ngrep,我已经验证了连接已启动,并且消息已从服务器发送 通过使用网关接口“gw”,我可以成功接收消息。然而,我想做的是在收到消息时触发com.example.Client.onMessage方法。我的理解是,这应该可以使用如下所示的ServiceActivator。这是真的还是我必须使用自己的专用线程来执行阻塞接收?谢谢 配置 必须在@配置
@配置
上配置@启用集成
和@集成组件扫描
。一般的Spring注释配置原则:。尽管有XML配置,但您根本不需要这些注释
的消息,则必须将其输入通道
配置为回复
输入
频道。在这种情况下,它们通过循环方式接收传入消息
员工,只需执行步骤2。虽然不清楚如何将消息发送到输入
频道@配置
上配置@启用集成
和@集成组件扫描
。一般的Spring注释配置原则:。尽管有XML配置,但您根本不需要这些注释
的消息,则必须将其输入通道
配置为回复
输入
频道。在这种情况下,它们通过循环方式接收传入消息
员工,只需执行步骤2。虽然不清楚如何将消息发送到输入
频道 <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" />
@EnableIntegration
@IntegrationComponentScan
@MessageEndpoint
public class Client {
@ServiceActivator
public void onMessage(byte[] received) {
//Not called
}
}