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. ZedGraph控件的使用

    http://blog.chinaunix.net/uid-20776117-id-1847015.html 在我们编写程序的时候,有时候是要做一些统计的,为了达到一目了然的效果,饼状图,曲线图,柱状 ...

  2. jmeter—打开jmx报com.thoughtworks.xstream.converters.ConversionException

    打开出错的jmx文件,查看出错行 由于缺少PerfMon Metrics Collector插件,所以报这个错误 下载地址(https://jmeter-plugins.org/downloads/a ...

  3. meta标签和JS实现页面刷新与重定向

    下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件.1) html的实现   1 2 3 4 5 6 <head& ...

  4. python findall() re.S

    官方文档:https://docs.python.org/3.6/library/re.html 教程:http://www.regexlab.com/zh/regref.htm re.findall ...

  5. 禁止Grid、TreeGrid列排序和列菜单

    Ext的Grid和Treegrid默认提供列菜单的功能,在列菜单中可以进行排序以及控制列显示状态. 在实际项目中,往往有些列是不需要用户看到的,因此就必须屏蔽列菜单的功能. 1.屏蔽Grid,包括Ed ...

  6. chrome从版本55开始,不再支持设置网页内容编码

    Hi Everyone,   Chrome 55 has removed the Encoding menu and Chrome will do auto-encoding detection no ...

  7. C/C++基础----函数

    用实参初始化形参时会忽略掉顶层const. 尽量使用常量引用,普通引用会限制所能接受的实参类型,也会给调用者误导. 管理数组实参的3种方法: 数组本身包含一个结束标记 传递指向数组首尾元素的指针 定义 ...

  8. nginx_auto_deny

    nginx auto deny 流量/访问限制脚本 https://files.cnblogs.com/files/ligao/nginx_deny_ip.tar.gz

  9. bzoj4419 发微博

    Description 刚开通的SH微博共有n个用户(1..n标号),在短短一个月的时间内,用户们活动频繁,共有m条按时间顺序的记录: ! x   表示用户x发了一条微博: + x y 表示用户x和用 ...

  10. java web 程序---javabean代码,出现错误。奇怪,无法解释的运行问题

    深夜吧.这个点11点半了 写了一个简单的javabean实例,发现没有任何代码书写的错误,但是问题就是程序运行会有问题,然后换一个包,重写一个,问题没了? 请问问题出现在哪里了?巧合?还是操作有误?这 ...