Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 收到消息时的spring集成回调_Java_Spring_Spring Integration - Fatal编程技术网

Java 收到消息时的spring集成回调

Java 收到消息时的spring集成回调,java,spring,spring-integration,Java,Spring,Spring Integration,spring和spring集成仍然是新手,请耐心听我说。=) 我已经设置了一个客户端,使用TCP连接到远程服务器。一旦建立连接,服务器就会发送消息。使用ngrep,我已经验证了连接已启动,并且消息已从服务器发送 通过使用网关接口“gw”,我可以成功接收消息。然而,我想做的是在收到消息时触发com.example.Client.onMessage方法。我的理解是,这应该可以使用如下所示的ServiceActivator。这是真的还是我必须使用自己的专用线程来执行阻塞接收?谢谢 配置 必须在@配置

spring和spring集成仍然是新手,请耐心听我说。=)

我已经设置了一个客户端,使用TCP连接到远程服务器。一旦建立连接,服务器就会发送消息。使用ngrep,我已经验证了连接已启动,并且消息已从服务器发送

通过使用网关接口“gw”,我可以成功接收消息。然而,我想做的是在收到消息时触发com.example.Client.onMessage方法。我的理解是,这应该可以使用如下所示的ServiceActivator。这是真的还是我必须使用自己的专用线程来执行阻塞接收?谢谢

配置

  • 必须在
    @配置
    上配置
    @启用集成
    @集成组件扫描
    。一般的Spring注释配置原则:。尽管有XML配置,但您根本不需要这些注释

  • 如果您希望从TCP接收到
    的消息,则必须将其
    输入通道
    配置为
    回复

  • 现在你的配置一团糟:有几个订阅者订阅了
    输入
    频道。在这种情况下,它们通过循环方式接收传入消息

  • 如果我理解正确,您应该移除所有
    员工,只需执行步骤2。虽然不清楚如何将消息发送到
    输入
    频道

  • 必须在
    @配置
    上配置
    @启用集成
    @集成组件扫描
    。一般的Spring注释配置原则:。尽管有XML配置,但您根本不需要这些注释

  • 如果您希望从TCP接收到
    的消息,则必须将其
    输入通道
    配置为
    回复

  • 现在你的配置一团糟:有几个订阅者订阅了
    输入
    频道。在这种情况下,它们通过循环方式接收传入消息

  • 如果我理解正确,您应该移除所有
    员工,只需执行步骤2。虽然不清楚如何将消息发送到
    输入
    频道

  • 是的,真是一团糟移除并添加轮询器。现在onMessage的调用和我预期的一样。谢谢。是的,真是一团糟移除并添加轮询器。现在onMessage的调用和我预期的一样。非常感谢。
      <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
        }
    }