🌐
GitHub
github.com › spring-cloud › spring-cloud-openfeign › issues › 594
Programmatic custom context inside FeignContext · Issue #594 · spring-cloud/spring-cloud-openfeign
August 16, 2021 - I can do @FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class). But if I create the clients manually via FeignClientBuilder (uses ApplicationContext) then I can't see a way to override stuff from FeignClientsConfiguration like an encoder.
Author: spring-cloud
🌐
Medium
amirsh71.medium.com › multiple-configurations-for-feign-clients-aeaacb8f0edd
Multiple Configurations for Feign Clients | by Amir Shokri | Medium
November 28, 2019 - These Feign clients need to adopt different authentication configuration. Here is the FooClient class. The FeignClient has a fooContextId, value and specific url and is configured in FooConfig class.
🌐
Getdocs
spring.getdocs.org › en-US › spring-cloud-docs › spring-cloud-openfeign › spring-cloud-feign › spring-cloud-feign-overriding-defaults.html
Untitled :: Spring Docs
If we want to create multiple feign clients with the same name or url so that they would point to the same server but each with a different custom configuration then we have to use contextId attribute of the @FeignClient in order to avoid name collision of these configuration beans.
🌐
HackerNoon
hackernoon.com › setting-up-multiple-configurations-for-feign-clients-a-step-by-step-guide-f51y3yb3
Setting Up Multiple Configurations for Feign Clients [A Step-by-Step Guide] | HackerNoon
June 21, 2020 - These Feign clients need to adopt different authentication configuration. Here is the FooClient class. The FeignClient has a fooContextId, value and specific url and is configured in FooConfig class.
🌐
GitHub
github.com › spring-cloud › spring-cloud-openfeign › blob › main › spring-cloud-openfeign-core › src › main › java › org › springframework › cloud › openfeign › FeignClient.java
spring-cloud-openfeign/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClient.java at main · spring-cloud/spring-cloud-openfeign
String contextId() default ""; · /** * @return The service id with optional protocol prefix. Synonym for {@link #value() * value}. */ @AliasFor("value") String name() default ""; · /** * @return the <code>@Qualifiers</code> value for the feign client.
Author: spring-cloud
🌐
Spring Cloud
cloud.spring.io › spring-cloud-openfeign › 2.1.x › multi › multi_spring-cloud-feign.html
1. Declarative REST Client: Feign - Spring Cloud Project
If we want to create multiple feign clients with the same name or url so that they would point to the same server but each with a different custom configuration then we have to use contextId attribute of the @FeignClient in order to avoid name collision of these configuration beans.
🌐
Spring
docs.spring.io › spring-cloud-openfeign › docs › current › reference › html
Spring Cloud OpenFeign
If we want to create multiple feign clients with the same name or url so that they would point to the same server but each with a different custom configuration then we have to use contextId attribute of the @FeignClient in order to avoid name collision of these configuration beans.
🌐
GitHub
github.com › spring-cloud › spring-cloud-openfeign › issues › 781
FeignClient contextId can not be resolved from config file · Issue #781 · spring-cloud/spring-cloud-openfeign
November 4, 2022 - FeignClient contextId can not be resolved from config file#781 · Copy link · dongyinuo · opened · on Nov 4, 2022 · Issue body actions · in spring-cloud-starter-openfeign v2.2.1.RELEASE, it works good, when i upgrade the starter to v2.2.9.RELEASE. it can't work, this is error: when i diff v2.2.1.RELEASE and v2.2.9.RELEASE, i find the changes, and, the latest tag and main branch are the same ·
Author: spring-cloud
🌐
TheCodeForge
thecodeforge.io › home › java › spring cloud feign client: declarative http in microservices
Feign Client in Spring Boot Microservices: Spring Cloud | TheCodeForge
May 23, 2026 - Per-client configuration is essential ... may need 30 seconds. ... contextId provides a unique Spring bean name for the Feign client, separate from the name attribute used for service routing....
Find elsewhere
🌐
GitHub
github.com › spring-cloud › spring-cloud-openfeign › issues › 960
Multiple Feign clients with same name fails application startup when url from configuration properties · Issue #960 · spring-cloud/spring-cloud-openfeign
December 22, 2023 - If we want to create multiple feign clients with the same name or url so that they would point to the same server but each with a different custom configuration then we have to use contextId attribute of the @FeignClient in order to avoid name ...
Author: spring-cloud
🌐
Spring
docs.spring.io › spring-cloud-openfeign › reference › spring-cloud-openfeign.html
Spring Cloud OpenFeign Features :: Spring Cloud Openfeign
If we want to create multiple Feign clients with the same name or url so that they would point to the same server but each with a different custom configuration then we have to use contextId attribute of the @FeignClient in order to avoid name collision of these configuration beans.
🌐
Stack Overflow
stackoverflow.com › questions › 78838391 › how-to-auto-generate-feign-client-in-java-kotlin-based-on-api-interface
spring - How to auto generate Feign client in java\kotlin based on api interface? - Stack Overflow
And Feign client · @FeignClient( contextId = "resourceClient", name = "service" ) interface ResourceClient : ResourceApi · Share · Improve this answer · Follow · answered Aug 8, 2024 at 15:09 · HolyDrug · 1111 silver badge44 bronze badges ...
🌐
Github
skywingzz.github.io › java › feign › Feign-Client
Feign Client Config 중복 사용 - Dev.skywing
August 6, 2019 - Feign Client Config 에 ContextId 가 중복되지 않게 명시적으로 지정한다.
🌐
Spring Cloud
cloud.spring.io › spring-cloud-openfeign › multi › multi_spring-cloud-feign.html
1. Declarative REST Client: Feign
If we want to create multiple feign clients with the same name or url so that they would point to the same server but each with a different custom configuration then we have to use contextId attribute of the @FeignClient in order to avoid name collision of these configuration beans.
🌐
GitHub
github.com › PlaytikaOSS › feign-reactive › issues › 604
Can we support the contextId of feign? I really need it, thank you · Issue #604 · PlaytikaOSS/feign-reactive
June 7, 2023 - Can we support the contextId of feign? I really need it, thank you · 👍React with 👍1intojun · No one assigned · No labels · No labels · No type · No projects · No milestone · None yet · No branches or pull requests ·
Author: PlaytikaOSS
🌐
Spring-doc
spring-doc.cn › spring-cloud-openfeign › 3.1.9 › index.en.html
1. Declarative REST Client: Feign (1. Declarative REST Client: Feign) | Spring Cloud OpenFeign3.1.9中文文档|Spring官方文档|SpringBoot 教程|Spring中文网
Spring Cloud creates a new ensemble ... an feign.Decoder, a feign.Encoder, and a feign.Contract. It is possible to override the name of that ensemble by using the contextId attribute of the @FeignClient annotation.spring-doc.cn ·...
Top answer
1 of 2
3

As you have seen in the documentation, you can set timeouts per specific client. But you have only configured it for feign client, not for hystrix command. Remember that they have independent timeouts.

I would recommend to use a configuration class instead of editing your application.yml in order to handle multiples feign clients with hystrix. The following example sets up a Feign.Builder where timeouts are being injected for Feign client and Hystrix command.

# application.yml
microservices:
    foo:
        feign:
            url: xxxx
            connect-timeout: 5s
            read-timeout: 5s
        hystrix:
            enabled: true
            timeout: 5s
@FeignClient(name = "foo",
             url = "${microservice.foo.feign.url}",
             configuration = FooFeignConfiguration.class)
public interface FooFeignRepository {
}
@Configuration
@RequiredArgsConstructor
public class FooFeignConfiguration {
    
    @Value("${microservice.foo.hystrix.enabled:true}")
    private final Boolean hystrixEnabled;

    @DurationUnit(value = ChronoUnit.MILLIS)
    @Value("${microservice.foo.feign.connect-timeout:5000}")
    private final Duration feignConnectTimeout;
    
    @DurationUnit(value = ChronoUnit.MILLIS)
    @Value("${microservice.foo.feign.read-timeout:5000}")
    private final Duration feignReadTimeout;
    
    @DurationUnit(value = ChronoUnit.MILLIS)
    @Value("${microservice.foo.hystrix.timeout:5000}")
    private final Duration hystrixTimeout;

    @Bean
    @Scope("prototype")
    public Feign.Builder feignBuilder() {
        return (hystrixEnabled ?
            HystrixFeign.builder()
                .options(new Request.Options(
                    (int) feignConnectTimeout.toMillis(), 
                    (int) feignReadTimeout.toMillis()))
                .setterFactory((target, method) -> {
                    return new SetterFactory.Default()
                        .create(target, method)
                        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                            .withExecutionTimeoutInMilliseconds((int) hystrixTimeout.toMillis()));
                }):
            Feign.builder())
        .retryer(Retryer.NEVER_RETRY);
    }
}
2 of 2
0

This config works for me.

Feign client:

@FeignClient(name="test", value = "test", url = "https://api.test.com")
public interface TestClient {

    @GetMapping("/test")
    ResponseEntity<Test> getProducts();
}

application.yml:

spring:
  cloud:
    openfeign:
      client:
        config:
          default:
            connectTimeout: 20000
            readTimeout: 60000
          test:
            connectTimeout: 2000
            readTimeout: 3000

pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
        <version>4.1.1</version>
    </dependency>
</dependencies>
🌐
Stack Overflow
stackoverflow.com › questions › 75421919 › how-to-specify-ribbon-configuration-for-a-specific-feign-client-in-a-spring-boot
How to specify Ribbon Configuration for a specific Feign client in a Spring Boot project having multiple Feign clients? - Stack Overflow
@FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class) https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html · Share · Improve this answer · Follow · answered Mar 14, 2023 at 22:29 · smile · 51699 silver badges1919 bronze badges ·