I am wondering if adding functionality to the Mono that I return from an ExchangeFilterFunction will be applied to the final Mono that gets returned. Basically I am wanting to clean up some of my client code by move some of the concerns out of the client class and into ExchangeFilterFunctions that I can add to the client, but my case is a bit different than a single call.
Basically I have something similar to the below code:
Flux.fromIterable(uris)
.parallel()
.runOn(Schedulers.parallel())
.flatMap(uri -> webClient.get()
.uri(uri)
.headers(headers -> headers.addAll(httpHeaders))
.retrieve()
.onStatus(
status -> status.is4xxClientError() || status.is5xxServerError(),
response -> response.bodyToMono(String.class)
.map(body -> new MyCustomException(body, response.statusCode())))
.bodyToMono(MyResponse.class)
.map(x -> Tuple.of(x, null))
.onErrorMap(ReadTimeoutException.class, th ->
new MyCustomException(ErrorResponseBuilder.buildError(th), HttpStatus.INTERNAL_SERVER_ERROR)))
.doOnEach(this::log)
.sequential();
My question is can I move out some of this logic for example the error handling and probably retry logic and additional logging to ExchangeFilterFunctions instead and if I do that will they still get applied when put into the Flux?
Also in the ExchangeFilterFunctions how would I be able to access the SubscriberContext because there is data in the context we need when logging like the unique id of the request that gets used for tracing.