feign和ribbon同时设置connectTimeout readTimeout,谁会先起作用

feign:
  client:
    config:
      default:
          connectTimeout: 1000000
          readTimeout: 1200000
  hystrix:
    enabled: true
ribbon:
  eager-load:
      enable: true
      clients: cloud-having
  ConnectTimeout: 150000
  ReadTimeout: 150000
  MaxAutoRetries: 0
  MaxAutoRetriesNextServer: 1
  retryableStatusCodes: 500,502,504
#  retryableStatusCodes: 500,502,504,404
  OkToRetryOnAllOperations: true

答案是feign的配置会覆盖掉ribbon的,具体还有一段有趣的故事,spring cloud gateway的作者貌似还不太清楚,有个路人给指出来了,还获得了gateway作者的称赞。

https://github.com/spring-cloud/spring-cloud-netflix/issues/696

好的,以下是一个简单的 Spring MVC 项目中集成 Eureka 和 Feign 的示例: 1. 引入依赖 首先,需要在项目的 pom.xml 文件中引入 Spring Cloud Eureka 和 Spring Cloud Feign 相关的依赖: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>2.2.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> <version>2.2.2.RELEASE</version> </dependency> ``` 2. 添加配置 接下来,需要在项目的配置文件中添加 Eureka Server 和 Feign Client 相关的配置: ```yaml spring: application: name: sample-service # 应用程序名称,注册到 Eureka Server 中 cloud: config: uri: http://localhost:8888 # Config Server 的地址 profile: dev # 配置文件的环境 label: master # Git 仓库的分支 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ # Eureka Server 的地址 feign: client: config: default: connectTimeout: 5000 # 连接超时时间 readTimeout: 5000 # 读取超时时间 ``` 这里假设 Config Server 的地址为 http://localhost:8888,Eureka Server 的地址为 http://localhost:8761/eureka/。 3. 创建 Feign Client 接下来,需要创建一个 Feign Client,用于访问另一个服务。这里以访问名为 `sample-service` 的服务为例: ```java @FeignClient(name = "sample-service") public interface SampleServiceClient { @GetMapping("/foo") String getFoo(); } ``` 这里使用 `@FeignClient` 注解来创建一个 Feign Client,指定服务名为 `sample-service`。`getFoo` 方法用于访问服务中的 `/foo` 接口,返回值为字符串类型。 4. 注册服务 最后,在项目启动时,需要将应用程序注册到 Eureka Server 中: ```java @SpringBootApplication @EnableDiscoveryClient @EnableFeignClients public class SampleApplication { public static void main(String[] args) { SpringApplication.run(SampleApplication.class, args); } } ``` 这里使用 `@EnableDiscoveryClient` 注解来启用服务注册功能,使用 `@EnableFeignClients` 注解来启用 Feign Client 功能。 需要注意的是,为了能够动态刷新配置,还需要在 `SampleServiceClient` 类上添加 `@RefreshScope` 注解。这样,在配置发生变化时,可以通过调用 `/actuator/refresh` 接口来刷新配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值