Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring different WebClient.Builder beans (not shared) for each @RetrofitClient instance? #25

Closed
dante-ricalde opened this issue Aug 9, 2021 · 2 comments · Fixed by #29
Assignees
Milestone

Comments

@dante-ricalde
Copy link

dante-ricalde commented Aug 9, 2021

Describe the bug
Hi guys, @OlgaMaciaszek,
at the docs about Retrofit with WebClient you can find information about how to configure a WebClient.Builder to be used under the hood for the Retrofit clients as shown by the following configuration:

@Configuration
@EnableRetrofitClients
class OkHttpClientConfig {

@Bean
@LoadBalanced
public WebClient.Builder okHttpClientBuilder() {
    return WebClient.builder();
    }
}

As you can notice, this configuration shows us how to use a shared WebClient.Builder to be used for all the @RetrofitClient instances.

I have the following question:
how Can I configure a different WebClient.Builder for each @RetrofitClient instance?
Imagine I have two client instances:

@RetrofitClient(name = "Api1Client")
public interface Api1Client {
    @GET("/")
    Mono<String> hello();
}

and

@RetrofitClient(name = "Api2Client")
public interface Api2Client {
    @GET("/")
    Mono<String> hello();
}

and I want to configure different timeouts and other properties for each client: 
for example for Api1Client I want to configure:

  • connectTimeout=300
  • readTimeout=1200
  • writeTimeout=800
  • 1 interceptor: Interceptor1
  • A proxyConfiguration:
 httpClient.tcpConfiguration(tcpClient -> tcpClient
                .proxy(proxy -> proxy
                    .type(ProxyProvider.Proxy.HTTP)
                    .host("ourproxy.com")
                    .port(8080)

and for client Api2Client I want to configure:

  • connectTimeout=600
  • readTimeout=3000
  • writeTimeout=2000
  • 2 interceptors: Interceptor2,Interceptor3

How can I configure 2 different WebClient Builders, one for Api1Client and other for Api2Client?
Is there a way to specify a different WebClient.Builder to be used in the @RetrofitClient?

Please, could you help me with these questions?
Thanks and Regards.

Sample
If possible, please provide a test case or sample application that reproduces
the problem. This makes it much easier for us to diagnose the problem and to verify that
we have fixed it.

@dante-ricalde dante-ricalde changed the title how to configure a different WebClient.Builder bean (not shared) for each @RetrofitClient instance? how to configure different WebClient.Builder beans (not shared) for each @RetrofitClient instance? Aug 9, 2021
@OlgaMaciaszek OlgaMaciaszek self-assigned this Aug 16, 2021
@OlgaMaciaszek
Copy link
Collaborator

Hi @dante-ricalde - it's currently not supported, but I think we might add it. Working on it now - should have a PR ready tomorrow.

@OlgaMaciaszek OlgaMaciaszek changed the title how to configure different WebClient.Builder beans (not shared) for each @RetrofitClient instance? Allow configuring different WebClient.Builder beans (not shared) for each @RetrofitClient instance? Sep 14, 2021
@OlgaMaciaszek OlgaMaciaszek added this to the 0.4.0-M2 milestone Sep 14, 2021
@dante-ricalde
Copy link
Author

Hi @dante-ricalde - it's currently not supported, but I think we might add it. Working on it now - should have a PR ready tomorrow.

Thank you so much @OlgaMaciaszek
I appreciate your help to add that feature
Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants