如何在不使用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) {...}
答案 0 :(得分:2)
@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
上的@BridgeTo
,因为您的输入渠道为PollableChannel
。