Boost Spring Boot Microservices with Reactive Feign: A Complete Guide
This article explains how to integrate feign-reactor with Spring Boot 2.7, covering OpenFeign features, reactive client setup, code examples, timeout configuration, and programmatic usage to enhance microservice communication.
Environment: SpringBoot 2.7.15 + feign-reactor-cloud 3.3.0
Introduction
OpenFeign is part of Spring Cloud, providing declarative service calls and load balancing. Its main features include support for Spring MVC annotations, built‑in load balancing, declarative remote calls, pluggable annotations, asynchronous communication, circuit‑breaker integration (e.g., resilience4j), and service discovery with Nacos or a load‑balancer.
However, OpenFeign does not support reactive clients such as Spring WebClient, and Spring Cloud OpenFeign also lacks this capability.
feign‑reactor extends Spring Cloud Feign with Reactor Netty support, enabling a reactive programming model, better asynchronous request handling, and additional features like load balancing, circuit‑breaker, and custom request/response handling.
Using feign‑reactor is essentially the same as OpenFeign, only the annotation names differ.
Environment Setup
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-spring-configuration</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-cloud</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<version>3.3.0</version>
</dependency>The feign-reactor-cloud dependency adds circuit‑breaker and load‑balancer support; feign-reactor-webclient provides a WebClient‑based implementation; feign-reactor-spring-configuration supplies Spring auto‑configuration.
Enable Reactive Feign
@SpringBootApplication
@EnableReactiveFeignClients
public class SpringcloudFeignReactorApplication { }Reactive Feign Interface Definition
@ReactiveFeignClient(
url = "http://localhost:8088/demos",
name = "demoReactorFeign",
fallback = DemoReactorFeignFallback.class,
configuration = {DemoReactorFeignConfig.class}
)
public interface DemoReactorFeign {
@GetMapping("/info/{id}")
Mono<Object> info(@PathVariable("id") Integer id);
}Fallback Implementation
public class DemoReactorFeignFallback implements DemoReactorFeign {
@Override
public Mono<Object> info(Integer id) {
return Mono.just("Request failed");
}
}Configuration Class
public class DemoReactorFeignConfig {
@Bean
public DemoReactorFeignFallback demoReactorFeignFallback() {
return new DemoReactorFeignFallback();
}
}Test Controller
@RestController
@RequestMapping("/reactor")
public class DemoController {
@Resource
private DemoReactorFeign demoReactorFeign;
@GetMapping("/{id}")
public Object info(@PathVariable("id") Integer id) {
return this.demoReactorFeign.info(id);
}
}Timeout Support
Timeouts can be configured globally:
reactive:
feign:
client:
config:
default:
options:
connectTimeoutMillis: 1000
readTimeoutMillis: 1000Or per‑client:
reactive:
feign:
client:
config:
demoReactorFeign:
options:
connectTimeoutMillis: 2000
readTimeoutMillis: 2000Programming Approach
Feign can also be used programmatically:
public class ProgramReactorFeignMain {
@Headers({"Accept: application/json"})
static interface DemoReactorFeign {
@RequestLine("GET /info/{id}")
Mono<Object> info(@Param("id") Integer id);
}
public static void main(String[] args) throws Exception {
DemoReactorFeign target = WebReactiveFeign
.<DemoReactorFeign>builder()
.target(DemoReactorFeign.class, "http://localhost:8088/demos");
target.info(6666).doOnNext(System.out::println).block();
}
}Done!
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
