Master Reactive Feign in Spring Boot 2.7: A Hands‑On Guide

This tutorial explains how to integrate Feign‑reactive into a Spring Boot 2.7 application, covering dependencies, reactive interface definitions, fallback handling, custom configurations, timeout, load‑balancing, and circuit‑breaker settings with complete code examples.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Master Reactive Feign in Spring Boot 2.7: A Hands‑On Guide

Introduction

Feign‑reactive is a framework for building reactive microservices in Spring Cloud, offering a concise Feign style, support for the Reactive programming model, asynchronous non‑blocking remote calls, seamless Spring Cloud integration, and extensibility through custom interceptors, encoders, and decoders.

Dependency Management

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

Practical Example

Remote Interface

@GetMapping("/demos/info/{id}")
public Object info(@PathVariable("id") Integer id) throws Exception {
    TimeUnit.SECONDS.sleep(3);
    Map<String, Object> result = new HashMap<>();
    result.put("code", 0);
    result.put("data", id);
    result.put("message", "success");
    return result;
}

Enable Reactive Feign

@EnableReactiveFeignClients
public class AppFeignReactorApplication {}

Reactive Feign Interface Definition

@ReactiveFeignClient(
    url = "http://localhost:8088/demos",
    name = "demoReactorFeign"
)
public interface DemoReactorFeign {
    @GetMapping("/info/{id}")
    Mono<Object> info(@PathVariable("id") Integer id);
}

Test Call

@Resource
private DemoReactorFeign demoReactorFeign;

@GetMapping("/{id}")
public Object info(@PathVariable("id") Integer id) {
    return this.demoReactorFeign.info(id);
}

Fallback Configuration

@ReactiveFeignClient(
    url = "http://localhost:8088/demos",
    name = "demoReactorFeign",
    fallback = DemoReactorFeignFallback.class,
    configuration = {DemoReactorFeignConfig.class}
)
public interface DemoReactorFeign {}

Fallback Implementation

public class DemoReactorFeignFallback implements DemoReactorFeign {
    @Override
    public Mono<Object> info(Integer id) {
        return Mono.just("请求失败");
    }
}

Custom Configuration

public class DemoReactorFeignConfig {
    @Bean
    public DemoReactorFeignFallback demoReactorFeignFallback() {
        return new DemoReactorFeignFallback();
    }
}

When a remote call fails or times out, the fallback defined above will be executed.

Timeout Configuration

reactive:
  feign:
    client:
      config:
        demoReactorFeign:
          options:
            connectTimeoutMillis: 2000
            readTimeoutMillis: 2000

Load Balancer Configuration

reactive:
  feign:
    loadbalancer:
      enabled: true

Circuit Breaker Configuration

reactive:
  feign:
    circuit:
      breaker:
        enabled: true

To activate the circuit breaker, add the following dependency:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>

Conclusion: Feign‑reactive works similarly to OpenFeign but uses reactive annotations; it enables asynchronous non‑blocking remote calls, improving performance and throughput of Spring Cloud applications.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaMicroservicesSpring BootSpring CloudReactive Feign
Spring Full-Stack Practical Cases
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.