2016-03-02 101 views
1

如何在不使用XML的情況下通過彈簧集成將2通道輸出到單通道。類似於以下問題Multiple channel's message comes into single channel通過彈簧集成註釋將多個通道發送到單通道

我有我的情況下2種PollableChannel豆,我希望將消息從兩個(非聚合)到單個@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) {...} 

回答

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}. 

您也可以考慮對@BridgeTo使用@Poller,因爲你的輸入通道PollableChannel

關於此事的參考手冊:http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/configuration.html#_creating_a_bridge_with_annotations

相關問題