springcloud demo---feign
1.配置文件
server:port: 8765 spring:application:name: feign-provider eureka:instance:lease-renewal-interval-in-seconds: 5lease-expiration-duration-in-seconds: 15client:healthcheck:enabled: trueservice-url:defaultZone: http://admin:123@localhost:8761/eureka/ feign:hystrix:enabled: true hystrix:command:default:execution:timeout:enabled: trueisolation:thread:timeoutInMilliseconds: 1000
2.依赖
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-ribbon</artifactId><version>2.0.0.RELEASE</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies>
3.启动类
package com.transsion;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients;@SpringBootApplication @EnableEurekaClient @EnableFeignClients public class FeignProviderApplication {public static void main(String[] args) {SpringApplication.run(FeignProviderApplication.class, args);}}
4.testController和testService
package com.transsion;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;@RestController public class TestController {@AutowiredTestService testService;@RequestMapping(value = "/test", method = RequestMethod.GET)public String helloConsumer() {//调用了绑定PROVIDER服务接口的客户端向服务发起/test接口的调用return testService.test();}}
package com.transsion;import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; //@FeignClient("PROVIDER"):绑定注册的服务:其中value为注册服务的applicationName,fallbac为熔断器的配置 @FeignClient(name = "PROVIDER",fallback = FallbackTest.class) public interface TestService {//绑定具体服务的REST接口@RequestMapping("/test")String test(); }
5.熔断类
package com.transsion;import org.springframework.stereotype.Component;//从@HystrixCommand(fallbackMethod)中的回调方法转换成回调类 @Component public class FallbackTest implements TestService{@Overridepublic String test() {return "fallback";} }
转载于:https://www.cnblogs.com/rainsakura/p/10407889.html
springcloud demo---feign相关推荐
- SpringCloud 中 Feign 核心原理,简单易懂!
目录 SpringCloud 中 Feign 核心原理 Feign远程调用的基本流程 Feign 远程调用的重要组件 Feigh 远程调用的执行流程 SpringCloud 中 Feign 核心原理 ...
- SpringCloud 中Feign原理(图解)
1 SpringCloud 中Feign原理 1.1 Feign简介 Feign是Netflix公司开源的轻量级rest客户端,使用Feign可以非常方便的实现Http 客户端.Spring Clou ...
- springcloud 实战 feign使用中遇到的相关问题
springcloud 实战 feign使用中遇到的相关问题 1.使用feign客户端调用其他微服务时,session没有传递成功,sessionId不一样. /*** @author xbchenf ...
- SpringCloud与Feign
SpringCloud只Feign如何实现负载均衡: 简介 Feign是一个声明式WebService客户端.使用Feign能让编写Web Service客户端更加简单, 它的使用方法是定义一个接口, ...
- SpringBoot+SpringCloud —— 使用Feign消费服务
转自:https://www.cnblogs.com/yimixiong/p/7927991.html 转:SpringBoot+SpringCloud -- 使用Feign消费服务 Feign简介 ...
- 文件上传结合SpringCloud的Feign进行服务调用
工作中一直使用的是SpringCloud,其中的多个组件的使用也已经有一段时间了,包括对组件的配置文件的编写,今天要讲的是SpringCloud中的一个远程服务调用的组件,使用Feign之后,我们调用 ...
- SpringCloud 中 Feign 调用添加 Oauth2 Authorization Header
SpringCloud 中 Feign 调用添加 Oauth2 Authorization Header SpringCloud 中通过 Feign 调用其他服务,当服务使用 Oauth2 授权的时候 ...
- springcloud feign 服务调用其他服务_微服务实战——SpringCloud与Feign集成
上一篇集成了ZuulGateway和Eureka并进行了测试.在实际场景中,我们肯定会有很多的微服务,而他们之间可能会存在相互调用的关系,那么,如何优雅的处理服务之间的调用问题呢?接下来就是我们要解决 ...
- springcloud使用feign进行远程服务调用
声明式服务调用SpringCloud Feign Feign客户端是一个web声明式http远程调用工具,提供了接口和注解方式进行调用,和ribbon都属于springcloud生态内客户端调用组件, ...
- springcloud 消费者 Feign (类似 webservice)
---------------------------------------------------------------------------------------------------- ...
最新文章
- 2016-8-18晨型养成第三天
- 居然之家忍“刮骨疗伤”之痛拥抱新零售
- 企业架构(五)——联邦企业架构(FEA)实施指南
- pycharm2019.2一个奇怪的bugger,执行后输出内容被莫名处理
- Nginx缓存的配置调优,Tengine安装和配置。
- TensorFlow:实战Google深度学习框架(二)实现简单神经网络
- number two
- 计算机系统-电路设计08-T触发器内部电路实现
- 数值分析(第五版) 第九章知识点总结
- 【暴力枚举】LeetCode 90. Subsets II
- 分水岭算法(Watershed Algorithm)
- 由嫦娥四号的中继卫星鹊桥,谈谈拉格朗日点
- 门户通专访草根站长九天狼:做站贵在坚持
- delphi模拟键盘按键
- 计算机f8进不到安全模式,简单几步解决win10开机按f8进不了安全模式的问题
- 拿什么拯救你的硬盘?十大绝招帮你忙
- JavaWEB10:Request、Response
- 三轴加速度传感器LIS3DH使用心得
- Java注解是怎么成功上位的?
- 手码万字-带你全面了解存储基础知识
热门文章
- 5s的app显示无法连接服务器,苹果5s无法连接app store解决方法汇总
- 使用pinctrl 和 gpio 子系统的字符设备驱动
- 树莓派开发4-串口通讯wiringpi库
- java c 序列化_Java 序列化
- 音频处理中频域转时域的恢复
- 图片格式转换(PNG or JPEG to EPS or PDF)
- LeetCode 53. Maximum Subarray--动态规划--C++,Python解法
- LLVM报错解决:/usr/bin/ld: cannot find -lz和/usr/bin/ld: cannot find -lncurses
- oracle 10g磁盘管理,Oracle 10g UNDO表空间过大导致磁盘空间不足的解决
- 基于阿里云用C/C++做了一个http协议与TCP协议的web聊天室的服务器——《干饭聊天室》