对,你绝对可以使用
ControlBus
关于这件事。对于Java DSL,它看起来像:
@Bean
public IntegrationFlow controlBus() {
return IntegrationFlowDefinition::controlBus;
}
要使用它,您需要:
@Autowired
@Qualifier("controlBus.input")
private MessageChannel controlBusChannel;
现在我们需要知道你的目标
IntegraionFlow
开始。什么会消耗消息。例如,我有:
@Bean
public IntegrationFlow fileFlow1() {
return IntegrationFlows.from("fileFlow1Input")
.handle(Files.outboundAdapter(tmpDir.getRoot()),
c -> c.id("fileWriting").autoStartup(false))
.get();
}
请注意
c.id("fileWriting").autoStartup(false)
. 这个
id
用于可以通过发送到控制总线的命令访问的端点bean。
这个
autoStartup(false)
这意味着它不会立即使用消息,但只能在我们呼叫时使用
start()
. 我是这样做的:
this.controlBusChannel.send(new GenericMessage<>("@fileWriting.start()"));
您应该在配置中确保类似的功能,以将消息消耗推迟到您需要的时间。