I am trying to create framework which should return 201 response. When a request is made to an API then i want to send back response immediately and process the request in background.
Flux.fromIterable(request.getApiRequests()).log().flatMap(item -> {
WebClient.RequestHeadersSpec apiCallSpec = WebClient.create(request.getBasePath())
.method(item.getHttpMethod()).uri(item.getPath()).accept(MediaType.valueOf(item.getAccept()))
.contentType(MediaType.valueOf(item.getContentType())).body(BodyInserters.fromObject(item.getPayload()));
return apiCallSpec.retrieve().bodyToMono(String.class);
}).subscribe();
return Mono.just("Created");
I want the flux part to happen in the background but as of now API waits and responds once whole flux is streamed.