我正试图通过控制总线启动文件入站通道适配器,但当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()")); // ????
// .....
}
所以我想问我如何访问'适配器' bean(或负责启动/停止操作的任何bean)来启动轮询过程。
谢谢。
除了.autoStartup(false)
,您还可以找到简单的.id()
钩子。
您将能够通过ControlBus精确启动所需的SourcePollingChannelAdapter
:
controlBusChannel.send(new GenericMessage<>("@myFilePollingAdapter.start()"));
您混淆了IntegrationFlow
代表其一堆bean的容器,并且不允许访问它们,因为它们无论如何都被注册为顶级bean。
虽然从1.2
版本开始,StandardIntegrationFlow
已经是SmartLifecycle
了,所以,你真的可以一次start/stop
所有相关的bean。包括第一个文件轮询器