Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE

1. Overview

In this tutorial, we’re going to describe the differences between Spring Cloud Netflix Feign and Spring Cloud OpenFeign.

2. Feign

Feign makes writing web service clients easier by providing annotation support that allows us to implement our clients with just interfaces.

Originally, Feign was created and released by Netflix as part of their Netflix OSS project. Today, it is an open-source project.

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.

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.

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

Similar to its predecessor, Spring Cloud OpenFeign integrates the predecessor project into the Spring Cloud ecosystem.

Conveniently, this integration adds support for Spring MVC annotations and provides the same HttpMessageConverters.

Let’s compare the Feign implementation found in the Spring Cloud OpenFeign to one using Spring Cloud Netflix Feign.

3. Dependencies

First, we must add the spring-cloud-starter-feign and spring-cloud-dependencies dependencies to our pom.xml file:

<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.

4. Implementation with Spring Cloud Netflix Feign

Now, we can use @EnableFeignClients to enable component scanning for any interfaces that use @FeignClient.

For every example that we developed using the Spring Cloud Netflix Feign project, we use the following imports:

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

Comparatively, our Spring Cloud OpenFeign tutorial contains the same example as the implementation with 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

Fundamentally, these two implementations of Feign are identical. We can ascribe this to Netflix Feign being the ancestor of OpenFeign.

However, Spring Cloud OpenFeign includes new options and features that are not available in Spring Cloud Netflix Feign.

Recently, we can get support for Micrometer, Dropwizard Metrics, Apache HTTP Client 5, Google HTTP client, and many more.

7. Conclusion

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.

Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – Microservices (eBook) (cat=Cloud/Spring Cloud)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.