GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feign/reactive at master · jkl0898/feign

Expand file tree

/

reactive

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

reactive

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src
src
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

README.md

Outline

Reactive Streams Wrapper

This module wraps Feign's http requests in a Reactive Streams Publisher, enabling the use of Reactive Stream Publisher return types. Supported Reactive Streams implementations are:

  • Reactor (Mono and Flux)
  • ReactiveX (RxJava) (Flowable only)

To use these wrappers, add the feign-reactive-wrappers module, and your desired reactive-streams implementation to your classpath. Then configure Feign to use the reactive streams wrappers.

public interface GitHubReactor {
      
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  Flux<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
  
  class Contributor {
    String login;
    
    public Contributor(String login) {
      this.login = login;
    }
  }
}

public class ExampleReactor {
  public static void main(String args[]) {
    GitHubReactor gitHub = ReactorFeign.builder()      
      .target(GitHubReactor.class, "https://api.github.com");
    
    List<Contributor> contributors = gitHub.contributors("OpenFeign", "feign")
      .collect(Collectors.toList())
      .block();
  }
}

public interface GitHubReactiveX {
      
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  Flowable<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
  
  class Contributor {
    String login;
    
    public Contributor(String login) {
      this.login = login;
    }
  }
}

public class ExampleRxJava2 {
  public static void main(String args[]) {
    GitHubReactiveX gitHub = RxJavaFeign.builder()      
      .target(GitHub.class, "https://api.github.com");
    
    List<Contributor> contributors = gitHub.contributors("OpenFeign", "feign")
      .collect(Collectors.toList())
      .block();
  }
}

Considerations

These wrappers are not reactive all the way down, given that Feign generated requests are synchronous. Requests still block, but execution is controlled by the Publisher and their related Scheduler. While this may not be ideal in terms of a fully reactive application, providing these wrappers provide an intermediate upgrade path for Feign.

Streaming

Methods that return java.util.streams Types are not supported. Responses are read fully, the wrapped in the appropriate reactive wrappers.

Iterable and Collections responses

Due to the Synchronous nature of Feign requests, methods that return Iterable types must specify the collection in the Publisher. For Reactor types, this limits the use of Flux as a response type. If you want to use Flux, you will need to manually convert the Mono or Iterable response types into Flux using the fromIterable method.

public interface GitHub {
      
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  Mono<List<Contributor>> contributors(@Param("owner") String owner, @Param("repo") String repo);
  
  class Contributor {
    String login;
    
    public Contributor(String login) {
      this.login = login;
    }
  }
}

public class ExampleApplication {
  public static void main(String[] args) {
    GitHub gitHub = ReactorFeign.builder()
      .target(GitHub.class, "https://api.github.com");
    
    Mono<List<Contributor>> contributors = gitHub.contributors("OpenFeign", "feign");
    Flux<Contributor> contributorFlux = Flux.fromIterable(contributors.block());
  }
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.