how to update reactive WebClient object to have Retry policy at a central place

179 Views Asked by At

I have an already existing application, and we are making calls to other application from this.

So, now, in our application we control the creation of WebClient object from a single place and then some other config are set on this like below :

    ObjectMapper objectMapper = new ObjectMapper();
        ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder()
                .codecs(configure ->
                        configure
                                .defaultCodecs()
                                .jackson2JsonDecoder(
                                        new Jackson2JsonDecoder(objectMapper)))
                .build();

        HttpClient httpClient = HttpClient.create()
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 12000)
                .responseTimeout(Duration.ofMillis(60000));

       
        return WebClient.builder()
                .exchangeStrategies(exchangeStrategies)
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .baseUrl(modelDeployConfig.getHost())
                .defaultHeaders( h -> {
                    h.setContentType(MediaType.APPLICATION_JSON);
                    h.setAccept(List.of(MediaType.APPLICATION_JSON));
                })
                .build();

Now, this webclient is build using this logic and used across the application. I want to impose some retry policies in our application which are common for all APIs.

But I dont find a way to do this at webclient level? any idea how to achieve this? any config settings available or any other way to suggest to achieve this where we can have some central retry policy which gets imposed on all APIs through this webclient object or by any other wrapper for webclient?

0

There are 0 best solutions below