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 ...
随机推荐
- Linux bash常用快捷键
移动光标 ctrl-a 光标移动到行首 ctrl-e 光标移动到行尾 ctrl+xx 在行首和光标位置直接切换 ctrl-b 光标左移一位 ctrl-f 光标右移一位 alt-b 光标左移一词 alt ...
- 紫书 习题 11-4 UVa 1660 (网络流拆点法)
这道题改了两天-- 因为这道题和节点有关, 所以就用拆点法解决节点的容量问题. 节点拆成两个点, 连一条弧容量为1, 表示只能经过一次. 然后图中的弧容量无限. 然后求最小割, 即最大流, 即为答案. ...
- pointer-events的css属性。使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为
pointer-events的css属性.使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为,比如当一个元素盖住了某个点击事件时可用. 现在Firefox3.6+/Safari4+/Ch ...
- 平凡主丛上的Yang-Mills理论
本文是复旦大学由丁青教授的暑期课程“Yang-Mills理论的几何及其应用”所作笔记,会有少许修正. 所需基础: 多元微积分学 微分方程(常微分方程,数学物理方程) 曲线曲面论(初等微分几何) 以下是 ...
- python __future__ 的几种特性
今天看tensorflow的代码,看到python里面有这么几句: from __future__ import absolute_import from __future__ import divi ...
- scratchIDE使用说明
scratchIDE使用说明
- [PYTHON]一个简单的单元測试框架
近期尝试了一下TDD(測试驱动)的模式.感觉效果不错.在此总结一下,同学们假设有更好的办法,一定要告诉我:) 1. 每一个功能模块(文件),配一个单元測试模块. 以手头这个项目为样例:有LogCat. ...
- IOS音频架构之Audio Unit
在前面的章节部分我们已经对IOS音频结构有了一个清晰的认识,知道Audio Unit是位于整个音频结构的最底层,这一层非常多API已经開始和硬件打交道了.所以比較复杂,有了前面的基础再来看这个部分就比 ...
- 10gR2 rac怎样重跑root.sh ?
原文博客链接地址:10gR2 rac怎样重跑root.sh ? 前几天遇到一客户的10205 rac,出现LMD进程IPC SEND TIMEOUT问题. 准备深入研究下Oracle RAC 的LMO ...
- word 的使用 —— 分页符与分节符
节的概念:节定义了一些格式, 如页边距.页面的方向.页眉和页脚,以及页码的顺序. 分节符是指为表示节的结尾插入的标记. 分节符的作用: 分节符起着分隔其前后文本格式的作用,如果删除了某个分节符,它前面 ...