1. Overview
1.概述
In this tutorial, we’re going to describe the differences between Spring Cloud Netflix Feign and Spring Cloud OpenFeign.
在本教程中,我们将介绍Spring Cloud Netflix Feign和Spring Cloud OpenFeign之间的区别。
2. Feign
2. 佯装
Feign makes writing web service clients easier by providing annotation support that allows us to implement our clients with just interfaces.
Feign通过提供注解支持,使我们能够仅用接口来实现我们的客户端,从而使编写 Web 服务客户端变得更加容易。
Originally, Feign was created and released by Netflix as part of their Netflix OSS project. Today, it is an open-source project.
最初,Feign是由Netflix创建并发布的,作为其Netflix OSS项目的一部分。今天,它是一个开源项目。
2.1. Spring Cloud Netflix Feign
2.1.Spring Cloud Netflix Feign
Spring Cloud Netflix integrates the Netflix OSS offerings into the Spring Cloud ecosystem. This includes Feign, Eureka, Ribbon, and a host of other tools and utilities. However, Feign was given its own Spring Cloud Starter to allow access to just Feign.
Spring Cloud Netflix将Netflix的OSS产品整合到Spring Cloud生态系统中。这包括Feign、Eureka、Ribbon以及大量其他工具和实用程序。然而,Feign被赋予了它自己的Spring Cloud Starter,以允许只访问Feign。
2.2. OpenFeign
2.2 OpenFeign
Ultimately, Netflix decided to stop using Feign internally and ceased its development. As a result of this decision, Netflix fully transferred Feign to the open-source community under a new project named OpenFeign.
最终,Netflix决定停止在内部使用Feign,并停止了它的开发。作为这一决定的结果,Netflix将Feign完全转移到了开源社区,在一个名为OpenFeign的新项目中。
Luckily, it continues to receive immense support from the open-source community and has seen many new features and updates.
幸运的是,它继续得到开源社区的巨大支持,并看到许多新的功能和更新。
2.3. Spring Cloud OpenFeign
2.3.Spring Cloud OpenFeign
Similar to its predecessor, Spring Cloud OpenFeign integrates the predecessor project into the Spring Cloud ecosystem.
与其前身类似,Spring Cloud OpenFeign将前身项目整合到Spring Cloud生态系统中。
Conveniently, this integration adds support for Spring MVC annotations and provides the same HttpMessageConverters.
方便的是,该集成增加了对Spring MVC注释的支持,并提供了相同的HttpMessageConverters。
Let’s compare the Feign implementation found in the Spring Cloud OpenFeign to one using Spring Cloud Netflix Feign.
让我们将Spring Cloud OpenFeign中的Feign实现与使用Spring Cloud Netflix Feign的实现进行比较。
3. Dependencies
3.依赖性
First, we must add the spring-cloud-starter-feign and spring-cloud-dependencies dependencies to our pom.xml file:
首先,我们必须将spring-cloud-starter-feign和spring-cloud-dependenciesdependencies添加到我们的pom.xml文件。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<versionId>1.4.7.RELEASE</versionID>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Please note that this library only works with Spring Boot 1.4.7 or earlier. Therefore our pom.xml must use compatible versions of any Spring Cloud dependencies.
请注意,这个库只适用于Spring Boot 1.4.7或更早版本。因此,我们的pom.xml必须使用任何Spring Cloud依赖的兼容版本。
4. Implementation with Spring Cloud Netflix Feign
4.用Spring Cloud Netflix Feign实现
Now, we can use @EnableFeignClients to enable component scanning for any interfaces that use @FeignClient.
现在,我们可以使用@EnableFeignClients来启用对任何使用@FeignClient的接口的组件扫描。
For every example that we developed using the Spring Cloud Netflix Feign project, we use the following imports:
对于我们使用Spring Cloud Netflix Feign项目开发的每个例子,我们都使用了以下导入。
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
The implementation of all features is exactly the same for the old and the new version.
所有功能的实现在新旧版本中是完全相同的。
5. Implementation with Spring Cloud OpenFeign
5.用Spring Cloud OpenFeign实现
Comparatively, our Spring Cloud OpenFeign tutorial contains the same example as the implementation with Spring Netflix Feign.
相对而言,我们的Spring Cloud OpenFeign教程包含与Spring Netflix Feign实现相同的示例。
The only difference here is that our imports are from a different package:
这里唯一的区别是,我们的进口来自不同的包。
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
Everything else is the same, which should come as no surprise due to the relation between these two libraries.
其他方面都是一样的,由于这两个库之间的关系,这应该不足为奇。
6. Comparison
6.比较
Fundamentally, these two implementations of Feign are identical. We can ascribe this to Netflix Feign being the ancestor of OpenFeign.
从根本上说,这两个Feign的实现是相同的。我们可以把这归因于Netflix Feign是OpenFeign的祖先。
However, Spring Cloud OpenFeign includes new options and features that are not available in Spring Cloud Netflix Feign.
然而,Spring Cloud OpenFeign包括Spring Cloud Netflix Feign中没有的新选项和功能。
Recently, we can get support for Micrometer, Dropwizard Metrics, Apache HTTP Client 5, Google HTTP client, and many more.
最近,我们可以获得对Micrometer、Dropwizard Metrics、Apache HTTP Client 5、Google HTTP client以及更多的支持。
7. Conclusion
7.结语
This article compared the Spring Cloud integrations of OpenFeign and Netflix Feign. As usual, you’ll find the sources over on GitHub for both Spring Cloud OpenFeign and Netflix Feign.
这篇文章比较了OpenFeign和Netflix Feign的Spring Cloud集成情况。像往常一样,您可以在GitHub上找到Spring Cloud OpenFeign和Netflix Feign的源代码。