Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kptfh/feign-reactive

Reactive Feign client based on Spring WebFlux
https://github.com/kptfh/feign-reactive

feign java reactive reactor ribbon rxjava2 spring-webclient spring-webflux

Last synced: about 17 hours ago
JSON representation

Reactive Feign client based on Spring WebFlux

Awesome Lists containing this project

README

        

Happy to announce that from now Java Reactive Feign client is officially backed by Playtika. All development will be conducted in Playtika fork https://github.com/Playtika/feign-reactive

[Subscribe to stay up to date 🙂](https://www.youtube.com/channel/UCAIRpdkVAj1RT6butHUV9yg)

# feign-reactive

[ ![Download](https://api.bintray.com/packages/kptfh/feign-reactive/client/images/download.svg) ](https://bintray.com/kptfh/feign-reactive/client/_latestVersion)

Use Feign with Spring WebFlux

## Overview

Implementation of Feign on Spring WebClient. Brings you the best of two worlds together :
concise syntax of Feign to write client side API on fast, asynchronous and
non-blocking HTTP client of Spring WebClient.

## Modules

**_feign-reactor-core_** : base classes and interfaces that should allow to implement alternative reactor Feign

**_feign-reactor-webclient_** : Spring WebClient based implementation of reactor Feign

**_feign-reactor-cloud_** : Spring Cloud implementation of reactor Feign (Ribbon/Hystrix)

**_feign-reactor-rx2_** : Rx2 compatible implementation of reactor Feign (depends on feign-reactor-webclient)

**_feign-reactor-jetty_** : experimental Reactive Jetty client based implementation of reactor Feign (doesn't depend on feign-reactor-webclient). In future will allow to write pure Rx2 version.
- have greater reactivity level then Spring WebClient. By default don't collect body to list instead starts sending request body as stream.
- starts receiving reactive response before all reactive request body has been sent
- process Flux<`String`> correctly in request and response body

## Usage

Write Feign API as usual, but every method of interface
- may accept `org.reactivestreams.Publisher` as body
- must return `reactor.core.publisher.Mono` or `reactor.core.publisher.Flux`.

```java
@Headers({ "Accept: application/json" })
public interface IcecreamServiceApi {

@RequestLine("GET /icecream/flavors")
Flux getAvailableFlavors();

@RequestLine("GET /icecream/mixins")
Flux getAvailableMixins();

@RequestLine("POST /icecream/orders")
@Headers("Content-Type: application/json")
Mono makeOrder(IceCreamOrder order);

@RequestLine("GET /icecream/orders/{orderId}")
Mono findOrder(@Param("orderId") int orderId);

@RequestLine("POST /icecream/bills/pay")
@Headers("Content-Type: application/json")
Mono payBill(Publisher bill);
}
```
Build the client :

```java

/* Create instance of your API */
IcecreamServiceApi client = ReactiveFeign
.builder()
.target(IcecreamServiceApi.class, "http://www.icecreame.com")

/* Execute nonblocking requests */
Flux flavors = icecreamApi.getAvailableFlavors();
Flux mixins = icecreamApi.getAvailableMixins();
```

or cloud aware client :

```java
IcecreamServiceApi client = CloudReactiveFeign.builder()
.setFallback(new TestInterface() {
@Override
public Mono get() {
return Mono.just("fallback");
}
})
.setLoadBalancerCommand(
LoadBalancerCommand.builder()
.withLoadBalancer(AbstractLoadBalancer.class.cast(getNamedLoadBalancer(serviceName)))
.withRetryHandler(new DefaultLoadBalancerRetryHandler(1, 1, true))
.build()
)
.target(IcecreamServiceApi.class, "http://" + serviceName);

/* Execute nonblocking requests */
Flux flavors = icecreamApi.getAvailableFlavors();
Flux mixins = icecreamApi.getAvailableMixins();
```

## Rx2 Usage

Write Feign API as usual, but every method of interface
- may accept `Flowable`, `Observable`, `Single` or `Maybe` as body
- must return `Flowable`, `Observable`, `Single` or `Maybe`.

```java
@Headers({"Accept: application/json"})
public interface IcecreamServiceApi {

@RequestLine("GET /icecream/flavors")
Flowable getAvailableFlavors();

@RequestLine("GET /icecream/mixins")
Observable getAvailableMixins();

@RequestLine("POST /icecream/orders")
@Headers("Content-Type: application/json")
Single makeOrder(IceCreamOrder order);

@RequestLine("GET /icecream/orders/{orderId}")
Maybe findOrder(@Param("orderId") int orderId);

@RequestLine("POST /icecream/bills/pay")
@Headers("Content-Type: application/json")
Single payBill(Bill bill);
```
Build the client :

```java

/* Create instance of your API */
IcecreamServiceApi client = Rx2ReactiveFeign
.builder()
.target(IcecreamServiceApi.class, "http://www.icecreame.com")

/* Execute nonblocking requests */
Flowable flavors = icecreamApi.getAvailableFlavors();
Observable mixins = icecreamApi.getAvailableMixins();
```

## Maven

```xml


bintray-kptfh-feign-reactive
bintray
https://dl.bintray.com/kptfh/feign-reactive

...

...


io.github.reactivefeign
feign-reactor-cloud
1.0.0


or if you don't need cloud specific functionality


io.github.reactivefeign
feign-reactor-webclient
1.0.0


or if you tend to use Rx2 interfaces


io.github.reactivefeign
feign-reactor-rx2
1.0.0

...

```

## License

Library distributed under Apache License Version 2.0.