netflix feign概述
1.什么是feign?feign的作用是什么?
Feign is a java to http client binder inspired by Retrofit, JAXRS-2.0, and WebSocket. Feign's first goal was reducing the complexity of binding Denominator uniformly to http apis regardless of restfulness.
2.为什么使用feign?
You can use tools like Jersey and CXF to write java clients for ReST or SOAP services. You can write your own code on top of http transport libraries like Apache HC. Feign aims to connect your code to http apis with minimal overhead and code. Via customizable decoders and error handling, you should be able to write to any text-based http api.
3.feign工作机制
Feign works by processing annotations into a templatized request. Just before sending it off, arguments are applied to these templates in a straightforward fashion. While this limits Feign to only supporting text-based apis, it dramatically simplified system aspects such as replaying requests. It is also stupid easy to unit test your conversions knowing this.
4.主要类及其层次结构

1.Feign's purpose is to ease development against http apis that feign restfulness. In implementation, Feign is a {@link Feign#newInstance factory} for generating {@link Target targeted} http apis.
重要方法:newInstance():Returns a new instance of an HTTP API, defined by annotations in the {@link Feign Contract}, for the specified {@code target}. You should cache this result.
2.Contract: Defines what annotations and values are valid on interfaces.
3.Client:Submits HTTP {@link Request requests}. Implementations are expected to be thread-safe.
4.Retryer:Cloned for each invocation to {@link Client#execute(Request, feign.Request.Options)}.Implementations may keep state to determine if retry operations should continue or not.
5.Encoder
Encodes an object into an HTTP request body. Like {@code javax.websocket.Encoder}. {@code
Encoder} is used when a method parameter has no {@code @Param} annotation. For example:
@POST
@Path("/")
void create(User user);
Example implementation:
public class GsonEncoder implements Encoder {
private final Gson gson;
public GsonEncoder(Gson gson) {
this.gson = gson;
}
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
template.body(gson.toJson(object, bodyType));
}
}
Form encoding If any parameters are found in {@link
feign.MethodMetadata#formParams()}, they will be collected and passed to the Encoder as a map.
Ex. The following is a form. Notice the parameters aren't consumed in the request line. A map
including "username" and "password" keys will passed to the encoder, and the body type will be
{@link #MAP_STRING_WILDCARD}.
@RequestLine("POST /")
Session login(@Param("username") String username, @Param("password") String
password);
6.Decoder
Decodes an HTTP response into a single object of the given {@code type}. Invoked when {@link
Response#status()} is in the 2xx range and the return type is neither {@code void} nor {@code
Response}. Example Implementation:
public class GsonDecoder implements Decoder {
private final Gson gson = new Gson();
@Override
public Object decode(Response response, Type type) throws IOException {
try {
return gson.fromJson(response.body().asReader(), type);
} catch (JsonIOException e) {
if (e.getCause() != null &&
e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
}
}
}
<h3>Implementation Note</h3> The {@code type} parameter will correspond to the {@link java.lang.reflect.Method#getGenericReturnType() generic return type} of an {@link feign.Target#type() interface} processed by {@link feign.Feign#newInstance(feign.Target)}. When writing your implementation of Decoder, ensure you also test parameterized types such as {@code List<Foo>}.
<h3>Note on exception propagation</h3> Exceptions thrown by {@link Decoder}s get wrapped in a {@link DecodeException} unless they are a subclass of {@link FeignException} already, and unless
the client was configured with {@link Feign.Builder#decode404()}.
7. InvocationHandlerFactory:Controls reflective method dispatch
netflix feign概述的更多相关文章
- SpringCloud学习笔记(六、SpringCloud Netflix Feign)
目录: feign简介 feign应用 feign简介: feign是一款Netflix开源的声明式.模板化的http客户端,它可以更加便捷.优雅的调用http api:SpringCloud对Net ...
- SpringCloud Netflix Feign
调用其它机器上的服务(远程调用)有2种技术:REST.RPC. REST 注入RestTempalte,服务提供者的url要写成RESTful风格,在url中传递参数. 如果参数很多,url会有一长串 ...
- netflix ribbon概述
LB方案分类 目前主流的LB方案可分成两类:一种是集中式LB, 即在服务的消费方和提供方之间使用独立的LB设施(可以是硬件,如F5, 也可以是软件,如nginx), 由该设施负责把访问请求通过某种策略 ...
- netflix turbine概述
1.turbine是什么?它的作用是什么? Turbine is a tool for aggregating streams of Server-Sent Event (SSE) JSON data ...
- Spring Cloud netflix feign【服务间通信】
一.简介 1,进程间通讯的本质是交换消息 2,服务间通信的两种方式 (1)RESTFul风格 (2)RPC风格 (3)两种风格的比较 3.基于RESTFul风格服务调用模型 4.基于Spring Cl ...
- 什么是 Netflix Feign?它的优点是什么?
Feign 是受到 Retrofit,JAXRS-2.0 和 WebSocket 启发的 java 客户端联编程序. Feign 的第一个目标是将约束分母的复杂性统一到 http apis,而不考虑其 ...
- 什么是Netflix Feign?它的优点是什么?
Feign是受到Retrofit,JAXRS-2.0和WebSocket启发的java客户端联编程序.Feign的第一个目标是将约束分母的复杂性统一到http apis,而不考虑其稳定性.在emplo ...
- Feign报错Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client
问题描述 使用Feign调用微服务接口报错,如下: java.lang.RuntimeException: com.netflix.client.ClientException: Load balan ...
- SpringCloud学习笔记(10)----Spring Cloud Netflix之声明式 REST客户端 -Feign的高级特性
1. Feign的默认配置 Feign 的默认配置 Spring Cloud Netflix 提供的默认实现类:FeignClientsConfiguration 解码器:Decoder feignD ...
随机推荐
- RHEL8.0-beta-1.ISO
https://pan.baidu.com/s/1Yh_xuz39xGRrCtGtwhuqQg RHEL-8.0-beta-1-x86_64-dvd.iso 文件名: E:\rhel-8. ...
- python学习笔记:第四天
day04: 一.计算求值 num += 1 等价于 num = num + 1num -= 1 等价于 num = num - 1num *= 2 等价于 num = num * 2num /= 2 ...
- 现代C++
C++ 是世界上最常用的编程语言之一. 编写良好的 C++ 程序是快速.高效的. 该语言比其他语言更加灵活,因为你可以使用它来创建各种应用,包括有趣刺激的游戏.高性能科学软件.设备驱动程序.嵌入式程序 ...
- 使用具体解释及源代码解析Android中的Adapter、BaseAdapter、ArrayAdapter、SimpleAdapter和SimpleCursorAdapter
Adapter相当于一个数据源,能够给AdapterView提供数据.并依据数据创建相应的UI.能够通过调用AdapterView的setAdapter方法使得AdapterView将Adapter作 ...
- BZOJ2179: FFT快速傅立叶 & caioj1450:【快速傅里叶变换】大整数乘法
[传送门:BZOJ2179&caioj1450] 简要题意: 给出两个超级大的整数,求出a*b 题解: Rose_max出的一道FFT例题,卡掉高精度 = =(没想到BZOJ也有) 只要把a和 ...
- 获取当前最上层controller
- (UIViewController *)topViewController { UIViewController *resultVC; resultVC = [self _topViewContr ...
- zzulioj--1825-- 会长爱数学(模拟)
1825: 会长爱数学 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 6 Solved: 2 SubmitStatusWeb Board Descr ...
- linux下修改完profile文件的环境变量后如何立即生效
方法1: 让/etc/profile文件修改后立即生效 ,可以使用如下命令: # . /etc/profile 注意: . 和 /etc/profile 有空格 方法2: 让/etc/profile文 ...
- struts2连接mysql多表查询
下载地址:http://download.csdn.net/detail/qq_33599520/9786567 项目结构: 代码: package com.mstf.action; import j ...
- 求推荐go语言开发工具及go语言应该以哪种目录结构组织代码?
go语言的开发工具推荐? go语言开发普通程序及开发web程序的时候,应该以哪种目录结构组织代码? 求推荐go语言开发工具及go语言应该以哪种目录结构组织代码? >> golang这个答案 ...