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;}@Overridepublic 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") Stringpassword);

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();@Overridepublic 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

转载于:https://www.cnblogs.com/davidwang456/p/6435311.html

netflix feign概述相关推荐

  1. [享学Feign] 一、原生Feign初体验,Netflix Feign or Open Feign?

    生命太短暂,不要去做一些根本没有人想要的东西.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习 ...

  2. 什么是Netflix Feign?它的优点是什么?

    Feign 是受到Retrofit,JAXRS-2.0 和WebSocket 启发的java 客户端联编程序.Feign 的第一个目标是将约束分母的复杂性统一到http apis,而不考虑其稳定性. ...

  3. 对比 Netflix Feign 和 OpenFeign

    对比 Netflix Feign 和 OpenFeign 本文主要描述介绍 Netflix Feign 和 OpenFeign 之间的差异,并比较一下Spring Cloud OpenFeign和使用 ...

  4. netflix ribbon概述

    LB方案分类 目前主流的LB方案可分成两类:一种是集中式LB, 即在服务的消费方和提供方之间使用独立的LB设施(可以是硬件,如F5, 也可以是软件,如nginx), 由该设施负责把访问请求通过某种策略 ...

  5. feign调用service_微服务之间的调用(Ribbon与Feign)

    概述 在前面的文章中,我们讲了使用Eureka作为服务注册中心,在服务启动后,各个微服务会将自己注册到Eureka server.那么服务之间是如何调用?又是如何进行负载均衡的呢?本文讲讲服务之间调用 ...

  6. Feign+Hystrix

    目录 写在前面 OpenFeign 首先了解Fiegn 什么是OpenFeign 简单使用 Feign的配置方式 部分配置详解 Hystrix 什么是Hystrix Hystrix简单使用 Hystr ...

  7. Feign实现服务调用

    上一篇博客我们使用ribbon+restTemplate实现负载均衡调用服务,接下来我们使用feign实现服务的调用,首先feign和ribbon的区别是什么呢? ribbon根据特定算法,从服务列表 ...

  8. Spring Cloud(四)服务提供者 Eureka + 服务消费者 Feign

    上一篇文章,讲述了如何通过RestTemplate + Ribbon去消费服务,这篇文章主要讲述如何通过Feign去消费服务. Feign简介 Feign是一个声明式的伪Http客户端,它使得写Htt ...

  9. java B2B2C Springboot电子商务平台源码-Feign 基本使用

    1. [microcloud-consumer-feign]为了可以使用到 feign 支持,需要修改 pom.xml 配置文件,引入相关依赖包:需要JAVA Spring Cloud大型企业分布式微 ...

最新文章

  1. LeetCod中等题之复数乘法
  2. bzoj 2565: 最长双回文串 manacher算法
  3. ubuntu12.04+fuerte 下跑通lsd-slam——数据集
  4. linux用户命令权限管理,Linux命令-用户、权限管理
  5. 论文中常用的几个Word2010技巧
  6. oracle升级12.2,Oracle 11.2.0.4升级到12.2.0.1
  7. springcloud工作笔记092---清理多余权限垃圾数据小工具
  8. new和delete创建和销毁二维数组
  9. vue-cli+webpack在生成的项目中使用bootstrap的方法
  10. Confluence 6 使用电子邮件可见
  11. 计算机教案解说词,小学微机室解说词初稿
  12. android迷你世界助手52,迷你世界助手盒子刷迷你币
  13. 2021年高压电工模拟考试题及高压电工操作证考试
  14. PAYPAL使用虚拟卡的会有优势吗?
  15. 垃圾回收器判断对象是否存活
  16. 07 HSV和HSL和YUV
  17. 人生之路小游戏代码2
  18. xshell远程传输文件过程
  19. 计算机主板属于什么垃圾分类类别,充电宝属于什么垃圾?废弃充电宝如何垃圾分类...
  20. android中 WIFI定位

热门文章

  1. netcore更新dll要停止_使 .NET Core 应用程序容器化
  2. timespan怎么比较大小_装饰画怎么挂都不好看?那是你不懂技巧!整理了一篇攻略,请拿好...
  3. 两个vlan之间如何通信_如何桥接两个不同的VLAN?
  4. 简易TCP客户端和服务端的实现
  5. win服务器自动发邮件,windows关机前执行脚本设置与关机blat自动发送邮件脚本模板...
  6. ubuntu虚拟机开机无法进入系统(initramfs)
  7. Linux下CMake简明教程(10) 定义宏来控制打印的信息
  8. Learning Deep Structured Semantic Models for Web Search using Clickthrough Data (DSSM)
  9. conda下用prefix创建虚拟环境会怎么样?
  10. 错误处理:one of the variables needed for gradient computation has been modified by inplace operation