java netflix.feign 和 openfeign 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49823158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Differences between netflix.feign & openfeign
提问by Menios
Introduction
介绍
I recently used netflix feign along with ribbon which was quite useful.
我最近使用了 netflix feign 和非常有用的功能区。
An Example of this is:
一个例子是:
@FeignClient(name = "ldap-proxy")
public interface LdapProxyClient {
@RequestMapping(path = "/ldap-proxy/v1/users/{userNameOrEMail}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
LdapUser search(@PathVariable("userNameOrEMail") String userNameOrEMail);
}
However, at some point I thought that instead of having to code all these definitions by hand (for an existing webservice), that I should see if a tool existed.
但是,在某些时候,我认为与其手动编写所有这些定义(对于现有的 Web 服务),我应该查看是否存在工具。
I stumbled across https://github.com/swagger-api/swagger-codegen
and saw that there are examples in which clients are generated, e.g. https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/java/feign.
我偶然发现https://github.com/swagger-api/swagger-codegen
有生成客户端的示例,例如https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/java/feign。
However, once I looked closely at the imports I noticed the following:
然而,一旦我仔细观察了进口,我注意到以下几点:
import feign.Feign;
import feign.Feign;
Netflix's opensource solution on the other hand has package names:
org.springframework.cloud.netflix.feign
.
另一方面,Netflix 的开源解决方案具有包名称:
org.springframework.cloud.netflix.feign
.
Additionally, I noticed that both use ribbon if available, but Netflix's notation is much cleaner with a lot happenning in the background. E.g. the @FeignClient
annotation class javadoc states:
此外,我注意到两者都使用功能区(如果可用),但 Netflix 的符号更清晰,后台发生了很多事情。例如,@FeignClient
注释类 javadoc 指出:
- Annotation for interfaces declaring that a REST client with that interface should be * created (e.g. for autowiring into another component). If ribbon is available it will be * used to load balance the backend requests, and the load balancer can be configured * using a
@RibbonClient
with the same name (i.e. value) as the feign client.
- 接口的注释声明应该创建具有该接口的 REST 客户端(例如,用于自动装配到另一个组件中)。如果ribbon可用,它将*用于对后端请求进行负载平衡,并且可以使用
@RibbonClient
与假客户端相同的名称(即值)来配置负载平衡器。
However in the Feign.feign
documentation (at https://github.com/OpenFeign/feign) I see:
但是在Feign.feign
文档中(在https://github.com/OpenFeign/feign)我看到:
RibbonClient overrides URL resolution of Feign's client, adding smart routing and resiliency capabilities provided by Ribbon.
Integration requires you to pass your ribbon client name as the host part of the url, for example myAppProd.
RibbonClient 覆盖了 Feign 客户端的 URL 解析,增加了 Ribbon 提供的智能路由和弹性能力。
集成要求您将功能区客户端名称作为 url 的主机部分传递,例如 myAppProd。
> MyService api =
> Feign.builder().client(RibbonClient.create()).target(MyService.class,
> "https://myAppProd");
So my questions are:
所以我的问题是:
- what is the history/relationship and differences between the two?
- what are the pros and cons of each?
- 两者之间的历史/关系和区别是什么?
- 各自的优缺点是什么?
Are they completely different projects with no relation, or did netflix just fork/utilize OpenFeign and modify it to be within their integrated cloud solution? Essentially, did netflix just acquire and integrate different technologies like Discovery, ribbon, and feign from open-source projects?
它们是完全没有关系的不同项目,还是 netflix 只是 fork/利用 OpenFeign 并将其修改为在他们的集成云解决方案中?本质上,Netflix 是否只是从开源项目中获取并整合了不同的技术,例如 Discovery、ribbon 和 feign?
回答by Eien
org.springframework.cloud.netflix.feign
is a part of Spring Cloud Netflixproject which is a part of Spring Cloud.
org.springframework.cloud.netflix.feign
是Spring Cloud Netflix项目的一部分,该项目是Spring Cloud的一部分。
Spring Cloud uses OpenFeign under the hood. It extends it to support Spring MVC annotations and makes it a first-class citizen in the Spring Environment by providing integrations for Spring Boot apps through autoconfiguration.
Spring Cloud 在底层使用 OpenFeign。它扩展了它以支持 Spring MVC 注释,并通过自动配置为 Spring Boot 应用程序提供集成,使其成为 Spring Environment 中的一等公民。
From the documentation:
从文档:
Feign is a declarative web service client. Spring Cloud adds support for Spring MVC annotations and for using the same HttpMessageConverters used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.
Feign 是一个声明式 Web 服务客户端。Spring Cloud 添加了对 Spring MVC 注释的支持,并支持使用 Spring Web 中默认使用的相同 HttpMessageConverters。Spring Cloud 集成了 Ribbon 和 Eureka,在使用 Feign 时提供负载均衡的 http 客户端。
Note that in the documentation there is a link to OpenFeign project.
请注意,文档中有一个指向 OpenFeign 项目的链接。
So if you use Spring Boot - it is better and easier to use Spring Cloud OpenFeign integrations.
因此,如果您使用 Spring Boot - 使用 Spring Cloud OpenFeign 集成会更好也更容易。
See also the source code.
另请参阅源代码。
回答by Paulo Merson
"Netflix feign" is the oldproject designation. The last version (dependency below) is dated July 2016.
“Netflix feign”是旧的项目名称。最后一个版本(下面的依赖项)发布于 2016 年 7 月。
compile group: 'com.netflix.feign', name: 'feign-core', version:'8.18.0' // OLD
"Open feign" is the newproject designation. It's the same project, but was moved to a different git repo and got a new group-id. Its versions start at 9.0.0.
“Open feign”是新的项目名称。这是同一个项目,但被转移到不同的 git 存储库并获得了新的组 ID。它的版本从 9.0.0 开始。
compile group: 'io.github.openfeign', name: 'feign-core', version: '10.0.1' // NEW
See this github issuefor a brief history of what happened. Most remarkably, you'll find out that Feign isn't used internally at Netflix anymore. :^o
有关所发生事件的简要历史,请参阅此 github 问题。最值得注意的是,您会发现 Netflix 内部不再使用 Feign。:^o