Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

10.5. Openfeign

10.5.1. Openfeign 扫描包配置

		
@EnableFeignClients(basePackages = {"cn.netkiller.openfeign"})		
		
		

10.5.2. 用户认证

		
@Configuration
@EnableFeignClients
public class FeignConfiguration {
    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
    }

    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor("user", "password");
    }
}		
		
		

10.5.3. 应用实例

		
@FeignClient(name="myServiceName", url="localhost:8888")
public interface OpenfeignService {
	@RequestMapping("/")
	public String getName();
}		
		
		

10.5.4. 配置连接方式

系统默认是 httpclient

10.5.4.1. httpclient

			
		<dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-httpclient</artifactId>
        </dependency>
			
			
			

httpclient

		
feign.httpclient.enabled=true
feign.httpclient.max-connections=1000
feign.httpclient.max-connections-per-route=50
		
			

10.5.4.2. okhttp

Maven 依赖

			
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-okhttp</artifactId>
</dependency>			
			
			

启用 okhttp

		
feign.httpclient.enabled=false
feign.okhttp.enabled=true
feign.httpclient.max-connections=1000
feign.httpclient.max-connections-per-route=50
		
			

10.5.5. 配置手册

https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/appendix.html