package bus.rpc.config;

import feign.Retryer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
* @Program: bus
* @Description: 描述
* @Author: bus
* @Date: 2025-02-24 14:39:33
**/
@Configuration
public class FeignConfiguration {

    /**
    * 创建Feign请求拦截器，在发送请求前设置认证的token,各个微服务将token设置到环境变量中来达到通用
    * @return
    */
    @Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new FeignBasicAuthRequestInterceptor();
    }

    /**
    * 重试间隔为1000ms，最大重试时间为5s,重试次数为0次
    * @return
    */
    @Bean
    public Retryer feignRetryer() {
        return new Retryer.Default(5000, SECONDS.toMillis(5), 0);
    }
}
