zoukankan      html  css  js  c++  java
  • SpringCloud常用配置

    hystrix的超时时间

    hystrix.command.default.execution.timeout.enabled=true
    hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000

    ribbon的超时时间

    #对当前实例的重试次数
    ribbon.MaxAutoRetries: 1

    #切换实例的重试次数
    ribbon.MaxAutoRetriesNextServer: 2

    #请求处理的超时时间
    ribbon.ReadTimeout: 60000

    #请求连接的超时时间
    ribbon.ConnectTimeout: 60000

    #对所有操作请求都进行重试
    ribbon.OkToRetryOnAllOperations: false

    feign开启Gzip压缩

    Spring Cloud Feign支持对请求与响应的压缩,以提高通信效率,在服务消费者配置文件开启压缩支持和压缩文件的类型即可

    #feign 请求与响应的压缩
    feign.compression.request.enabled=true
    feign.compression.response.enabled=true
    feign.compression.request.mime-types=text/xml,application/xml,application/json
    feign.compression.request.min-request-size=2048
    
    feign开启日志

    feign开启日志有两种方式,一种是使用配置文件,一种是使用java代码,下面将介绍代码方式
    创建FeignLogConfig类,添加一个LoggerBean

    @Configuration
    public class FeignLogConfig {
    
    /**
     * 日志level有4个级别
     * 1.NONE,不记录任何日志
     * 2.BASIC,仅记录请求方法、URL以及响应状态码和执行时间
     * 3.HEADRES,除了BASIC以外的还会记录请求和响应的头信息
     * 4.FULL,所有
     * @return
     */
    @Bean
    Logger.Level feignLogger(){
        return Logger.Level.FULL;
    }
    feign替换JDK默认的URLConnection为okhttp
    使用okhttp,能提高qps,因为okhttp有连接池和超时时间进行调优
    • 在服务消费者中,添加feign-okhttp依赖
    <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-okhttp</artifactId> </dependency>
    feign.httpclient.enabled=false
    feign.okhttp.enabled=true

    • 创建OkHttpConfig类,添加okhttp的bean
    • /**
       * 配置okhttp与连接池
       * ConnectionPool默认创建5个线程,保持5分钟长连接
       */
      @Configuration
      @ConditionalOnClass(Feign.class)
      @AutoConfigureBefore(FeignAutoConfiguration.class)
      public class OkHttpConfig {
       
      @Bean
      public okhttp3.OkHttpClient okHttpClient(){
          return new okhttp3.OkHttpClient.Builder()
                  //设置连接超时
                  .connectTimeout(10 , TimeUnit.SECONDS)
                  //设置读超时
                  .readTimeout(10 , TimeUnit.SECONDS)
                  //设置写超时
                  .writeTimeout(10 , TimeUnit.SECONDS)
                  //是否自动重连
                  .retryOnConnectionFailure(true)
                  .connectionPool(new ConnectionPool(10 , 5L, TimeUnit.MINUTES))
                  .build();
      }
     
  • 相关阅读:
    手把手带你画一个 时尚仪表盘 Android 自定义View
    新手自定义view练习实例之(二) 波浪view
    新手自定义view练习实例之(一) 泡泡弹窗
    增加辅助的数据库组件
    解决Plugin is too old,please update to a more recent version,or set ANDROID_DAILY_OVERRIDE..
    Android 自定义View -- 简约的折线图
    android 开源图表库MPChart最简单使用方法示例教程Demo--折线图 柱状图
    改善database schema
    题解报告:hdu 2057 A + B Again
    hdu 2087 剪花布条(KMP入门)
  • 原文地址:https://www.cnblogs.com/linqing001/p/14149298.html
Copyright © 2011-2022 走看看