如何在不使用XML的情况下通过Spring集成将2个通道输出到单个通道。与以下问题类似,多个频道的消息进入单个频道
我的上下文中有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) {...}
@Bean("Channel1")
@BridgeTo("Channel1and2")
PollableChannel c1() {...}
@Bean("Channel2")
@BridgeTo("Channel1and2")
PollableChannel c2() {...}
注意te@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}.
您还可以考虑使用@Poller
on @BridgeTo
,因为您的输入通道是PollableChannel
。
关于此问题的参考手册:http : //docs.spring.io/spring-integration/docs/latest-ga/reference/html/configuration.html#_creating_a_bridge_with_annotations
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句