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

Default http client (Client.Default) seems not taking 'spring.cloud.openfeign.httpclient' properties when creating feign client with FeignClientBuilder #1028

Open
Siegolas opened this issue May 4, 2024 · 1 comment

Comments

@Siegolas
Copy link

Siegolas commented May 4, 2024

I'm creating feign clients using method FeignClientBuilder(context). I'm trying to check the effect of "maxConnections" and "maxConnectionsPerRoute" properties from "spring.cloud.openfeign.httpclient" it seems they are not applied.
I'm applying the properties:

spring:
    cloud:
        openfeign:
            httpclient:
                max-connections: 1
                max-connections-per-route: 1

I'm using spring-cloud-openfeign version 4.0.3

A sample of how I create the feign client:

private val target = FeignClientBuilder(context)
        .forType(PhoneMaskingServiceFeignClientExtension::class.java, PHONEMASKINGSERVICE)
        .url(phoneMaskingServiceConfig.url)
        .customize {
            it
                .encoder(GsonEncoder())
                .decoder(gsonDecoder)
                .requestInterceptors(RequestInterceptors.create())
                .requestInterceptor(OpenApiInterceptor())
                .requestInterceptor(HeadersInterceptor(headersConfig.getForwardingHeaders()))
                .requestInterceptor(
                    BasicAuthRequestInterceptor(
                        phoneMaskingServiceConfig.api.user,
                        phoneMaskingServiceConfig.api.password
                    )
                )

        }.build()

However when I force the client to be ApacheHttpClient one and I manually apply the mentioned properties it works as expected and when applying load testing the execution produces timeouts

private val target = FeignClientBuilder(context)
        .forType(PhoneMaskingServiceFeignClientExtension::class.java, PHONEMASKINGSERVICE)
        .url(phoneMaskingServiceConfig.url)
        .customize {
            it
                .encoder(GsonEncoder())
                .decoder(gsonDecoder)
                .client(
                    ApacheHttpClient(
                        HttpClientBuilder.create()
                            .setMaxConnPerRoute(1)
                            .setMaxConnTotal(1)
                            .build()
                    )
                )                
                .requestInterceptors(RequestInterceptors.create())
                .requestInterceptor(OpenApiInterceptor())
                .requestInterceptor(HeadersInterceptor(headersConfig.getForwardingHeaders()))
                .requestInterceptor(
                    BasicAuthRequestInterceptor(
                        phoneMaskingServiceConfig.api.user,
                        phoneMaskingServiceConfig.api.password
                    )
                )

        }.build()

So is there anything wrong in my setup? How can I achieve httpclient props max-connections and max-connections-per-route from "spring.cloud.openfeign.httpclient" are properly applied when using FeignClientBuilder? Is FeignClientBuilder applying "spring.cloud.openfeign.httpclient" properties for the default http client?

Thanks in advance

@smileatom
Copy link

smileatom commented May 29, 2024

@Siegolas I just had to debug this sadly . The httpclient property will not be applied to a client located at:

openfeign:
  httpclient:

nor will it work under the default client
If you want it to be set properly move the httpclient underneth your named feign client

my-feignclient:
  httpclient:
    foo:

That will work.

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

No branches or pull requests

3 participants