简体   繁体   中英

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:

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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