OpenFeign更换HTTPClient提升性能

时间:2024-6-24    作者:老大夫    分类: SpringCloud


ApaCheHTTP5代替默认浏览器HTTPURLConection,性能会提升。

  1. 关闭重试配置

  1. 修改pom
<!-- httpclient5-->
<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
    <version>5.3</version>
</dependency>
<!-- feign-hc5-->
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-hc5</artifactId>
    <version>13.1</version>
</dependency>
  1. 配置开启说明application.yml
server:
  port: 80

spring:
  application:
    name: cloud-consumer-openfeign-order
  ####Spring Cloud Consul for Service Discovery
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        prefer-ip-address: true #优先使用服务ip进行注册
        service-name: ${spring.application.name}
    openfeign:
      client:
        config:
          default:
            connectTimeout: 4000 #连接超时时间
                        readTimeout: 4000 #读取超时时间
            httpclient:
          hc5:
            enabled: true
          #cloud-payment-service:
            #connectTimeout: 4000 #连接超时时间
                        #readTimeout: 4000 #读取超时时间


扫描二维码,在手机上阅读

推荐阅读: