1. 依赖

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

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

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>

</dependencies>
</dependencyManagement>
</project>

2. 启动类

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class FeignApplication {

public static void main(String[] args) {
SpringApplication.run(FeignApplication.class, args);
}

@Bean
protected Logger.Level level(){
return Logger.Level.FULL;
}
}

3. feign

@FeignClient(name="hello-service",fallback=fallbackHelloFeignClient.class)
public interface HelloFeignClient {

@RequestMapping(value="/hello")
public String hello() throws InterruptedException;

@Component
static class fallbackHelloFeignClient implements HelloFeignClient{

@Override
public String hello() throws InterruptedException {
return “error”;
}

}
}

4. 业务

@RestController
public class HelloFeignController {

@Autowired
private HelloFeignClient client;

@GetMapping("/hello")
public String hello() throws InterruptedException {
return client.hello();
}
}

5 配置

server:
port: 8095
spring:
application:
name: feign-consumer
eureka:
client:
serviceUrl:
defaultZone: http://ym-eureka-server1:8759/eureka/
instance:
preferIpAddress: true
ribbon:
ConnectTimeout: 6000
ReadTimeout: 6000
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 15000
feign:
hystrix:
enabled: true
logging:
level:
com:
ym: debug

spring coud feign的更多相关文章

  1. spring coud Feign常用配置

    Ribbon配置 在Feign中配置Ribbon非常简单,直接在application.properties中配置即可,如: # 设置连接超时时间 ribbon.ConnectTimeout=500 ...

  2. 笔记:Spring Cloud Feign Ribbon 配置

    由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...

  3. 笔记:Spring Cloud Feign Hystrix 配置

    在 Spring Cloud Feign 中,除了引入了用户客户端负载均衡的 Spring Cloud Ribbon 之外,还引入了服务保护与容错的工具 Hystrix,默认情况下,Spring Cl ...

  4. 笔记:Spring Cloud Feign 其他配置

    请求压缩 Spring Cloud Feign 支持对请求与响应进行GZIP压缩,以减少通信过程中的性能损耗,我们只需要通过下面二个参数设置,就能开启请求与响应的压缩功能,yml配置格式如下: fei ...

  5. 笔记:Spring Cloud Feign 声明式服务调用

    在实际开发中,对于服务依赖的调用可能不止一处,往往一个接口会被多处调用,所以我们通常会针对各个微服务自行封装一些客户端类来包装这些依赖服务的调用,Spring Cloud Feign 在此基础上做了进 ...

  6. 第六章:声明式服务调用:Spring Cloud Feign

    Spring Cloud Feign 是基于 Netflix Feign 实现的,整合了 Spring Cloud Ribbon 和 Spring Cloud Hystrix,除了提供这两者的强大功能 ...

  7. Spring Cloud Feign Ribbon 配置

    由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...

  8. Spring Cloud feign

    Spring Cloud feign使用 前言 环境准备 应用模块 应用程序 应用启动 feign特性 综上 1. 前言 我们在前一篇文章中讲了一些我使用过的一些http的框架 服务间通信之Http框 ...

  9. 微服务架构之spring cloud feign

    在spring cloud ribbon中我们用RestTemplate实现了服务调用,可以看到我们还是需要配置服务名称,调用的方法 等等,其实spring cloud提供了更优雅的服务调用方式,就是 ...

随机推荐

  1. 【转】每天一个linux命令(46):vmstat命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/12/25/2833108.html vmstat是Virtual Meomory Statistics( ...

  2. 通过手动安装来启动ZStack

    当您使用手动安装手册完成ZStack的安装之后,您可以继续进行一些必要的配置 以便用它来自动云环境.ZStack的管控工具zstack-ctl会安装到每一个ZStack管理节点,您可以使用它来控制本地 ...

  3. mac 使用

    普通键盘操作mac电脑,快捷键: 快捷键 功能 ctrl + a 到行首 ctrl + e 到行尾 ctrl + up 打开任务控制(窗口平铺) window + tab 选择任务 ctrl + le ...

  4. 优化Django ORM中的性能问题(含prefetch_related 和 select_related)

    Django是个好工具,使用的很广泛. 在应用比较小的时候,会觉得它很快,但是随着应用复杂和壮大,就显得没那么高效了.当你了解所用的Web框架一些内部机制之后,才能写成比较高效的代码. 怎么查问题 W ...

  5. UOJ 188 【UR #13】Sanrd——min_25筛

    题目:http://uoj.ac/problem/188 令 \( s(n,j)=\sum\limits_{i=1}^{n}[min_i>=p_j]f(j) \) ,其中 \( min_i \) ...

  6. sql server 2008数据库 降为 sql server 2005数据库 最终方案总结

    由于xx原因,sql server 要降级,所以有了下文.... 一 直接 通过sql server 自带工具 生成脚本即可,具体操作方法如下: 1.打开 Microsoft Sql Server M ...

  7. 设计模式初学者笔记:Builder模式

    [作者:byeyear    Email:byeyear@hotmail.com    首发:cnblogs    转载请注明] 在本文的开头,先森森的鄙视下自己……将Builder模式反反复复读了七 ...

  8. js在html文件中的解析顺序

    我们可以将JavaScript代码放在html文件中任何位置,但是我们一般放在网页的head或者body部分. 放在<head>部分 最常用的方式是在页面中head部分放置<scri ...

  9. Java-Runoob-高级教程-实例-数组:04. Java 实例 – 数组反转

    ylbtech-Java-Runoob-高级教程-实例-数组:04. Java 实例 – 数组反转 1.返回顶部 1. Java 实例 - 数组反转  Java 实例 以下实例中我们使用 Collec ...

  10. 学习笔记之Kubernetes

    Kubernetes | Production-Grade Container Orchestration https://kubernetes.io/ Kubernetes is an open-s ...