spring-integrationspring-webclient

Spring Integration WebFlux outboundGateway in splitter flow causes synchronous splitter to be asynchronous


I have a Spring Integration flow where a list of requests is split with a serial splitter so each subflow and so each request is processed sequentially. The sub flow sends the request to another system via HTTPS using a WebFlux.outboundGateway to allow using the modern features of WebClient. What I have found is that after the HTTP request is submitted, the Splitter starts processing the next request in its list rather than waiting for the subflow to complete.

How can I configure this to make the splitter process the sub flows in a serial manner?

flow
    .transform( Message.class, message -> generateRequests( message ) )
    .split()
    .handle( 
        WebFlux.outboundGateway( this::resolveUri, webClient )
            .httpMethod( HttpMethod.GET )
            .expectedResponseType( String.class )
    )
    .aggregate()


Solution

  • The WebFlux.outboundGateway() is async by nature and produces a Mono as a reply which is evaluated on the .publishOn(Schedulers.boundedElastic()) before publishing real reply to the output channel.

    To make it blocking, consider to wrap this handle() into a gateway():

    .gateway((subFlow) -> subFlow
         .handle( 
            WebFlux.outboundGateway( this::resolveUri, webClient )
                .httpMethod( HttpMethod.GET )
                .expectedResponseType( String.class )))