> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/spring-cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/spring-cloud/fu-wu-xiao-fei-zhe/fu-wu-xiao-fei-zhe-feign.md).

# 服务消费者（Feign）

Feign客户端是一个web声明式http远程调用工具，提供了接口和注解方式进行调用。

## 环境搭建&#x20;

### Maven依赖信息

```markup
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
```

### feign客户端接口

controller

```java
	@Autowired
	private MemberApifeign memberApifeign;

	@RequestMapping("/feignMember")
	public String feignMember() {
		return memberApifeign.getMember();
	}
```

feign客户端接口

```java
// name 指定服务名称
@FeignClient(name = "app-itmayiedu-member")
public interface MemberApifeign {

	@RequestMapping("/getMember")
	public String getMember();

}
```

项目启动加上@EnableFeignClients

```java
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class AppOrder {
	public static void main(String[] args) {
		SpringApplication.run(AppOrder.class, args);
	}
}
```

## feign继承特性

在使用声明式feign客户端工具的时候，因为书写的方式代码可能会产生重复，可以使用feign客户端集成方式减少代码。

## 配置Feign客户端超时时间

```yaml
###设置feign客户端超时时间
ribbon:
###指的是建立连接所用的时间，适用于网络状况正常的情况下，两端连接所用的时间。
 ReadTimeout: 5000
###指的是建立连接后从服务器读取到可用资源所用的时间。 
 ConnectTimeout: 5000
```

[SpringCloud-Feign【超时时间设置】](https://blog.csdn.net/qq_38526573/article/details/91355785)
