spring-cloud-feign案例
主要依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>1.0.7RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
</dependencies>
FeignClient 代码
@FeignClient("bar-service")
public interface BarFeign{
@RequestMapping(method = RequestMethod.GET ,value = "/bar" )
String getBar();
}
@FeignClient("foo-service")
public interface FooFeign{
@RequestMapping(method = RequestMethod.GET ,value = "/foo" )
String getFoo();
}
App入口程序代码及调用FeignClient的代码
@RestController
@SpringBootApplication
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEurekaClient
@EnableFeignClients
public class Application{
@AutoWired
FooFeign foo;
@AutoWired
BarFeign bar;
@RequestMapping("/foo")
public String foo(){
return foo.getFoo();
}
@RequestMapping("/bar")
public String bar(){
return bar.getBar();
}
public static main(String[] args){
SpringApplication.run(Application.class,args);
}
}
测试可发现foo 和 bar 分别调用了foo-service 和bar-service服务
使用FeignClient可以使当前服务于其他服务更容易的集成
spring-cloud-feign案例的更多相关文章
- 笔记: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提供了更优雅的服务调用方式,就是 ...
- Spring Cloud Feign 在调用接口类上,配置熔断 fallback后,输出异常
Spring Cloud Feign 在调用接口类上,配置熔断 fallback后,出现请求异常时,会进入熔断处理,但是不会抛出异常信息. 经过以下配置,可以抛出异常: 将原有ErrorEncoder ...
- RestTemplate OR Spring Cloud Feign 上传文件
SpringBoot,通过RestTemplate 或者 Spring Cloud Feign,上传文件(支持多文件上传),服务端接口是MultipartFile接收. 将文件的字节流,放入ByteA ...
随机推荐
- VRP相关知识整理
一.扩展问题分类: ★ the capacitated vehicle routing problem (CVRP) , 即classical VRP ★ the vehicle routing pr ...
- jenkis编译报错:需要class,interface或enum
现象: 1.jenkis编译报错:需要class,interface或enum 2.使用ant进行编译ok. 解决方法: 1. Jenkis重新编译一个以前成功的svn版本,直至编译成功. 2.Jen ...
- YAR 并行RPC框架研究
前几天,部门召开了PHP技术峰会 学习会议,大家分别对这次会议的PPT 做了简单的介绍, 其中提到了 鸟哥[惠新辰]的一篇PPT<微博LAMP 演变>,如果谁有需要可以去谷歌搜,或者去 h ...
- PHP.4-DIV+CSS标准网页布局准备工作(下)
DIV+CSS标准网页布局准备工作 区块属性(区块模型) 属 性 描 述 Margin(注) 是定义区块外边界与上级元素距离的属性,用1到4个值来设置元素的边界,每个值都是长度.百分比或者auto,百 ...
- android源码编译过程
1.下载好android源码包. 2.装好vm,ubuntu(如果能在实体机装linux更好). 3.安装所需要的deb包 在终端执行如下命令: sudo apt-get install flex b ...
- C中的回调函数
C语言中应用回调函数的地方非常多,如Nginx中: struct ngx_command_s { ngx_str_t name; ngx_uint_t type; char *(*set)(ngx_c ...
- 为dedecms v5.7的ckeditor添加jwplayer插件
dedecms v5.7的默认编辑器是ckeditor,不过用的是php版本的,默认的工具栏不在config.js里面配置,而是在ckeditor.inc.php里面配置,默认的工具栏是$toolba ...
- 在Visual Studio 的 “一般处理程序 ” .ashx 文件中如何创建Session 对象
只需要继承这个接口即可实现创建Session对象. IHttpHandler,System.Web.SessionState.IHttpSessionState 代码示例: public class ...
- Web.config加密和解密
在系统部署的时候,大家都会遇到关于用户凭证的安全性问题,而对于数据库连接的相关的信息,有些时候客户也需要我们对其加密,防止信息泄露,在此将加密和解的方法记录于此: 首先用管理员的权限启动cmd命令窗口 ...
- 【转载】LinkedIn是如何优化Kafka的
http://www.wtoutiao.com/p/18d5RY0.html 在LinkedIn的数据基础设施中,Kafka是核心支柱之一.来自LinkedIn的工程师曾经就Kafka写过一系列的专题 ...