Spring Cloud
  • Introduction
  • 网站架构演变过程
    • 微服务架构
  • Spring Cloud 简介
  • 服务的注册与发现
    • 其他知识
      • Zookeeper与Eureka区别
      • DiscoveryClient 与@EnableEurekaServer
    • Zookeeper
    • Consul
    • Eureka
      • 搭建注册中心
      • 高可用注册中心
      • Eureka详解
  • 服务消费者
    • RestTemplate
    • 服务消费者(rest+ribbon)
      • 此时架构
    • 服务消费者(Feign)
  • 断路器(Hystrix)
    • 基础入门
  • API Gateway(Zuul)
    • 基础入门
  • 分布式配置中心(Config)
    • 基础入门
  • SpringCloud Bus
  • 链路跟踪(Sleuth)
  • 数据流(Stream)
  • Dubbo
    • Untitled
Powered by GitBook
On this page
  • 环境搭建
  • Maven依赖信息
  • feign客户端接口
  • feign继承特性
  • 配置Feign客户端超时时间

Was this helpful?

  1. 服务消费者

服务消费者(Feign)

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

环境搭建

Maven依赖信息

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

feign客户端接口

controller

	@Autowired
	private MemberApifeign memberApifeign;

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

feign客户端接口

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

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

}

项目启动加上@EnableFeignClients

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

feign继承特性

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

配置Feign客户端超时时间

###设置feign客户端超时时间
ribbon:
###指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的时间。
 ReadTimeout: 5000
###指的是建立连接后从服务器读取到可用资源所用的时间。 
 ConnectTimeout: 5000
Previous此时架构Next断路器(Hystrix)

Last updated 4 years ago

Was this helpful?

SpringCloud-Feign【超时时间设置】