日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

netflix feign概述

發布時間:2025/4/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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;}@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概述的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。