简体   繁体   English

等待spring集成流程完成

[英]Wait for spring integration flow to complete

I have this simple flow that reads files from a directory and does some actions:我有一个从目录中读取文件并执行一些操作的简单流程:

   @Bean
public IntegrationFlow processMessage() {
    return IntegrationFlows
            .from(messageFlow1Directory(), c -> c
                    .id("flow1")
                    .autoStartup(false)
                    .poller(Pollers.fixedDelay(30000)
                    .errorChannel(errorMessageChannel())))
            .publishSubscribeChannel(s -> s
                    .subscribe(f -> f.handle("flow1Service", "processMessage"))
                    .subscribe(f -> f.handle(otherAction)))
            .get();
}

I have achieved to start it with a controlBus in one of my main classes:我已经实现了在我的一个主要课程中使用 controlBus 启动它:

public static void main(String[] args) throws InterruptedException {
    SpringApplication.run(Flow1Main.class, args);
    controlBus.send(new GenericMessage<>("@flow1.start()"));
}

What I want is to wait for the flow to complete before sending a stop() and exiting the main class. How can I do that?我想要的是在发送 stop() 并退出主 class 之前等待流程完成。我该怎么做?

Thank you in advance for your help预先感谢您的帮助

If you only want to process one message, it would be easier to use a gateway to send the message, instead of starting/stopping a poller.如果您只想处理一条消息,使用网关发送消息会更容易,而不是启动/停止轮询器。

https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM