首页 > 解决方案 > Spring Integration DSL如何将消息异步发送到其他内部通道

问题描述

现在我接受一个 http 请求来处理耗时的任务。所以我想先回复请求者,然后使用其他异步流来处理它。

我尝试在 handler() 方法中使用 CompletableFuture.runAsync ,然后使用 MessageChannel.send 来做。但我认为应该有更优雅的方式

 @Bean
    public IntegrationFlow testFlow(){
        return IntegrationFlows.from("requestChannel")//accept an request
                .handle(handlerSomeThing())//do something
                .handle()?// how to send message to main and reply quickly
                .enrichHeaders(c->c.header(HttpHeaders.STATUS_CODE,HttpStatus.OK))
                .get();
    }

 @Bean
    public IntegrationFlow mainFlow(){
        return IntegrationFlows.from("mainChannel")//accept an request
                .handleMainLogic()//handler main logic

                .get();
    }

标签: spring-integrationspring-integration-dsl

解决方案


用户 a publishSubscribeChannel

看到这个答案

添加一个任务执行器,以便两个子流并行运行。


推荐阅读