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. PHP经典乱码“口”字与解决办法

    这几天看了看 Ajax 的基础知识,在练习一个简单的 请求和响应时,PHP 返回来的数据 在 IE 中开头总显示 一个 “锘” 字!上网 Baidu 了一下,发现这是由于 系统 处理 UTF-8 的方 ...

  2. ace 在线编辑器 知识点

    ace 常用方法: 功能 语句 设置值 editor.setValue("the new text here"); // or session.setValue 获取值 edito ...

  3. Apache关闭VirtualHost的Log日志记录

    有时我们的apache产生的日志是超大的并且 没什么用处,这时我们就可以关闭了,关闭apache日志很简单,直接ErrorLog off或 # CustomLog即可. Web server(ex: ...

  4. 【shell】sed命令

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为:         sed ...

  5. Zabbix监控windows的CPU利用率和其他资源

    zabbix的WEB端--配置-模板--Template OS Windows--项目--创建项目 名称:UserPerfCountercpu 键值:UserPerfCountercpu 数据类型:数 ...

  6. 利用x-requested-with判断请求是否是Ajax请求

    在服务器端判断request来自Ajax请求(异步)还是传统请求(同步):         两种请求在请求的Header不同,Ajax 异步请求比传统的同步请求多了一个头参数 1.传统同步请求参数 a ...

  7. java-appium-527进阶-1 UiAutomator1&2区别和封装

    1.UiAutomator和UiAtumator2的区别: 1.1 UiAutomator1有关于id定位的策略 UiAutomator1 id定位在resourceid匹配失败时,会匹配conten ...

  8. 【转载】Vmware Vconverter从物理机迁移系统到虚拟机P2V

    本文完整记录了如何从物理服务器,保持所有环境配置信息,纹丝不动的迁移到虚拟机上,俗称 P2V .采用的工具是VMware公司的 VMware vcenter vconverter standalone ...

  9. oletools下载安装及rtfobj使用

    rtf内嵌对象分析提取工具rtfobj是oletools的一部分 oletools各个版本下载地址https://bitbucket.org/decalage/oletools/downloads/ ...

  10. 新手搭建 nginx + php (LNMP)

    配置源 纯净的Centos 6.5系统 配置163yum源 (这个比较简单,百度能解决很多问题) 开始 安装  开发软件包:yum  -y groupinstall  "Developmen ...