【问题标题】:Multiple channels sent to single channel with spring-integration annotations使用弹簧集成注释将多个通道发送到单个通道
【发布时间】:2016-06-16 00:31:33
【问题描述】:

如何在不使用 XML 的情况下通过 spring 集成将 2 个通道输出到单个通道。类似下面的问题Multiple channel's message comes into single channel

我的上下文中有 2 个 PollableChannel bean,我希望将消息从两个(非聚合)路由到单个 @ServiceActivator,即完成如下操作:

@Bean("Channel1") PollableChannel c1() {...}
@Bean("Channel2") PollableChannel c2() {...}

?? How to interleave/combine Channel1 and Channel2 into a single channel

...
@ServiceActivator(inputChannel = "Channel1and2")
void handle(msg: MyMessage) {...}

【问题讨论】:

    标签: java spring annotations spring-integration


    【解决方案1】:
    @Bean("Channel1") 
    @BridgeTo("Channel1and2")
    PollableChannel c1() {...}
    
    @Bean("Channel2") 
    @BridgeTo("Channel1and2")
    PollableChannel c2() {...}
    

    注意@BridgeTo注解。来自其 JavaDocs:

    * Messaging Annotation to mark a {@link org.springframework.context.annotation.Bean}
    * method for a {@link org.springframework.messaging.MessageChannel} to produce a
    * {@link org.springframework.integration.handler.BridgeHandler} and Consumer Endpoint.
    * <p>
    * The {@link org.springframework.messaging.MessageChannel} {@link org.springframework.context.annotation.Bean}
    * marked with this annotation is used as the {@code inputChannel} for the
    * {@link org.springframework.integration.endpoint.AbstractEndpoint}
    * and determines the type of endpoint -
    * {@link org.springframework.integration.endpoint.EventDrivenConsumer} or
    * {@link org.springframework.integration.endpoint.PollingConsumer}.
    

    您也可以考虑在@BridgeTo 上使用@Poller,因为您的输入通道是PollableChannel

    关于此事的参考手册:http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/configuration.html#_creating_a_bridge_with_annotations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-29
      • 2013-05-29
      • 2018-08-04
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      • 2017-07-27
      相关资源
      最近更新 更多