> 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)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/spring-cloud/fu-wu-xiao-fei-zhe/fu-wu-xiao-fei-zhe-feign.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
