2016-08-23 52 views
1

我試圖通過控制總線啓動文件入站通道適配器,但我收到異常,而ExpressionCommandMessageProcessor試圖解析我的命令。如何通過控制總線啓動入站通道適配器?

這是我入站通道適配器配置:

@Bean(name = "inboundChannelAdapter") 
public IntegrationFlow inputFilesReadingFlow() 
{ 
     return IntegrationFlows 
        .from(s -> s.file(new File(inputDirectory)) 
           .filter(new AcceptAllFileListFilter<File>()), 
         e -> e.poller(Pollers.fixedDelay(FILE_POLLER_RATE)) 
           .autoStartup(false) 
         ) 
        .handle(messageProcessingService) 
        .channel(fileOutputChannel) 
        .get(); 
} 

@Bean 
public IntegrationFlow controlBusFlow() 
{ 
    return IntegrationFlows.from("controlBusChannel").controlBus().get(); 
} 

在我的集成測試,我已經自動連接控制總線豆:

@Autowired 
private MessageChannel controlBusChannel; 

@Test 
public void testInboundChannelAdapter() 
{ 
    controlBusChannel.send(new GenericMessage<String>("@'inboundChannelAdapter.<property_name_placeholder>'.start()")); // ???? 

    // ..... 
} 

所以我想問我怎麼可以訪問「適配器'bean(或任何負責啓動/停止操作的bean)啓動輪詢過程。

謝謝。

回答

1

隨着.autoStartup(false)你可以找到簡單的.id()掛鉤。

有了這樣你就可以開始通過控制總線正是期望SourcePollingChannelAdapter

controlBusChannel.send(new GenericMessage<>("@myFilePollingAdapter.start()")); 

你混淆IntegrationFlow代表容器的一堆豆子,不允許以訪問他們,因爲他們無論如何都被註冊爲頂級bean。

雖然隨着版本1.2StandardIntegrationFlow開始是SmartLifecycle了,所以,你真的可以start/stop一下子那些與豆類。包括第一個File Poller之一。

+0

非常感謝回覆。我設法解決它使用特定的ID。另外我發現這個答案(http://stackoverflow.com/a/23916788/222002),同時等待我的問題的答覆和自動裝配SourcePollingChannelAdapter也爲我工作。 – Alex

相關問題