如何通过控制总线启动入站通道适配器?

时间:2016-08-23 22:06:22

标签: java spring spring-integration

我正在尝试通过控制总线启动文件入站通道适配器,但我在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();
}

在我的集成测试中,我有自动控制的总线bean:

@Autowired
private MessageChannel controlBusChannel;

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

    // .....
}

所以我想问一下如何访问'adapter'bean(或任何bean负责启动/停止操作)来启动轮询过程。

谢谢。

1 个答案:

答案 0 :(得分:1)

.autoStartup(false)一起,你可以找到简单的.id()钩子。

通过ControlBus可以启动完全想要的SourcePollingChannelAdapter

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

你感到困惑的是IntegrationFlow代表了一堆bean的容器而且不允许访问它们,因为无论如何它们都被注册为顶级bean。

虽然从版本1.2 StandardIntegrationFlow开始已经是SmartLifecycle,所以,您真的可以start/stop同时使用所有相关的bean。包括第一个文件轮询器。

相关问题