我尝试通过控制总线启动文件入站 channel 适配器,但在 ExpressionCommandMessageProcessor 尝试解析我的命令时遇到异常。
这是我的入站 channel 适配器配置:
@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()
Hook 。
这样您就可以通过 ControlBus 启动所需的 SourcePollingChannelAdapter
:
controlBusChannel.send(new GenericMessage<>("@myFilePollingAdapter.start()"));
您感到困惑的是,IntegrationFlow
表示其一堆 Bean 的容器,并且不允许访问它们,因为它们无论如何都注册为顶级 Bean。
尽管从 1.2
版本开始 StandardIntegrationFlow
已经是 SmartLifecycle
,所以,您确实可以启动/停止
所有内容立即那些相关的 bean 。包括第一个文件轮询器。
关于java - 如何通过控制总线启动入站 channel 适配器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39111415/