All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.ishow.starter.rpc.basic.FeignPropertiesInjector Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package cn.ishow.starter.rpc.basic;

import cn.ishow.starter.common.injector.AbstractProfileEnvironmentPostProcessor;
import cn.ishow.starter.common.util.spring.PropertySourceUtils;
import cn.ishow.starter.rpc.constant.RpcConst;
import org.springframework.boot.SpringApplication;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * feign需要的默认参数,其参数存放在defaultSource中优先级最低
 *
 * @author bucheng
 * @create 2022/5/16 22:22
 */
public class FeignPropertiesInjector extends AbstractProfileEnvironmentPostProcessor {

    @Override
    public void onAllProfiles(ConfigurableEnvironment env, SpringApplication application) {
        //开启压缩功能
        PropertySourceUtils.addToDefaultSource(env, "feign.compression.request.enabled", true);
        PropertySourceUtils.addToDefaultSource(env, "feign.compression.request.mime-types", "application/json");
        PropertySourceUtils.addToDefaultSource(env, "feign.compression.request.min-request-size", 10);
        PropertySourceUtils.addToDefaultSource(env, "feign.compression.response.useGzipDecoder", true);
        PropertySourceUtils.addToDefaultSource(env, "feign.compression.response.enabled", true);
        //开启hystrix功能
        PropertySourceUtils.addToDefaultSource(env, "feign.hystrix.enabled", true);
        //使用信号量模式
        PropertySourceUtils.addToDefaultSource(env, "hystrix.command.default.execution.isolation.strategy", "SEMAPHORE");
        //默认信号量的数量
        PropertySourceUtils.addToDefaultSource(env, "hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests", 100);
        //关闭hystrix的超时配置
        PropertySourceUtils.addToDefaultSource(env, "hystrix.command.default.execution.timeout.enabled", false);
        //关闭重试策略
        PropertySourceUtils.addToDefaultSource(env, "ribbon.MaxAutoRetries", 0);
        PropertySourceUtils.addToDefaultSource(env, "ribbon.MaxAutoRetriesNextServer", 0);
        //注入全局超时配置
        PropertySourceUtils.addToDefaultSource(env, RpcConst.GLOBAL_CONNECTION_TIMEOUT,3000);
        PropertySourceUtils.addToDefaultSource(env, RpcConst.GLOBAL_READ_TIMEOUT,5000);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy