spring coud feign
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的更多相关文章
- spring coud Feign常用配置
Ribbon配置 在Feign中配置Ribbon非常简单,直接在application.properties中配置即可,如: # 设置连接超时时间 ribbon.ConnectTimeout=500 ...
- 笔记:Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
- 笔记:Spring Cloud Feign Hystrix 配置
在 Spring Cloud Feign 中,除了引入了用户客户端负载均衡的 Spring Cloud Ribbon 之外,还引入了服务保护与容错的工具 Hystrix,默认情况下,Spring Cl ...
- 笔记:Spring Cloud Feign 其他配置
请求压缩 Spring Cloud Feign 支持对请求与响应进行GZIP压缩,以减少通信过程中的性能损耗,我们只需要通过下面二个参数设置,就能开启请求与响应的压缩功能,yml配置格式如下: fei ...
- 笔记:Spring Cloud Feign 声明式服务调用
在实际开发中,对于服务依赖的调用可能不止一处,往往一个接口会被多处调用,所以我们通常会针对各个微服务自行封装一些客户端类来包装这些依赖服务的调用,Spring Cloud Feign 在此基础上做了进 ...
- 第六章:声明式服务调用:Spring Cloud Feign
Spring Cloud Feign 是基于 Netflix Feign 实现的,整合了 Spring Cloud Ribbon 和 Spring Cloud Hystrix,除了提供这两者的强大功能 ...
- Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
- Spring Cloud feign
Spring Cloud feign使用 前言 环境准备 应用模块 应用程序 应用启动 feign特性 综上 1. 前言 我们在前一篇文章中讲了一些我使用过的一些http的框架 服务间通信之Http框 ...
- 微服务架构之spring cloud feign
在spring cloud ribbon中我们用RestTemplate实现了服务调用,可以看到我们还是需要配置服务名称,调用的方法 等等,其实spring cloud提供了更优雅的服务调用方式,就是 ...
随机推荐
- PHP 中的对象传递
<?php class A { public $age = 0; public $username = ""; public $obj = null; } $a = new ...
- idea引入svn
刚想在idea看一个svn的项目代码,结果发现导入项目后,idea在右下角弹出了Event Log窗口,里面的红色小字 Can't use Subversion command line client ...
- 【linux】Linux 进程状态
linux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有 ...
- 织梦ask标签的调用
EDE 问答首页调用标签 标签名称: ask 功能说明:问答调用标签 适用范围:全局使用 基本语法: {dede:ask row='6' qtype='new' tid='0' titlelen='2 ...
- springMVC学习(9)-全局异常处理
一.异常处理思路: 系统中异常包括两类:预期异常和运行时异常RuntimeException,前者通过捕获异常从而获取异常信息,后者主要通过规范代码开发.测试通过手段减少运行时异常的发生. 系统的da ...
- 尽量少嵌套无用的div;外部文件尽量使用link而不要使用用@import
最近的工作又学到了很多东西,在这里记录一下. 1,尽量少嵌套无用的div,这个问题领导很严肃的跟我提过很多次,因为我很喜欢用很多div,而且有很多div都是无存在意义的.后来领导给了我一些资料,我看了 ...
- Linux 简单命令查询CPU、内存、网卡等信息
[转自]Linux查询CPU.内存.网卡等信息 看CPU信息(型号)# cat /proc/cpuinfo | grep name | cut -f2 -d: |uniq -c 1 Int ...
- Unreal Engine 4(虚幻UE4)GameplayAbilities 插件入门教程(五)技能属性集(AttributeSet)
如果没有完成前面的教程,请前往学习.先上一段理论介绍(源于https://wiki.unrealengine.com/GameplayAbilities_and_You#GameplayTasks): ...
- 第3章 文件I/O(3)_内核数据结构、原子操作
3. 文件I/O的内核数据结构 (1) 内核数据结构表 数据结构 主要成员 文件描述符表 ①文件描述符标志 ②文件表项指针 文件表项 ①文件状态标志(读.写.追加.同步和非阻塞等状态标志) ②当前文件 ...
- extract 用法说明
PHP extract() 函数从数组中把变量导入到当前的符号表中 定义和用法 PHP extract() 函数从数组中把变量导入到当前的符号表中. 对于数组中的每个元素,键名用于变量名,键值用于变量 ...