Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactive support for feign cleint

I am planning to refactor my microservice from blocking implementation to reactive API using spring webflux. I have few doubts:

1) whether to choose annotation based controller or functional router? 2) is there any support for reactive feign client available?

Please help.

like image 213
Chandresh Mishra Avatar asked Dec 17 '18 14:12

Chandresh Mishra


2 Answers

I'm finding this question incomplete without proper usage example of how things should be set up.

Since op did not mention target language I'm feeling like to share Kotlin setup that works in my case:

build.gradle.kts

implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.playtika.reactivefeign:feign-reactor-core:2.0.22")
implementation("com.playtika.reactivefeign:feign-reactor-spring-configuration:2.0.22")
implementation("com.playtika.reactivefeign:feign-reactor-webclient:2.0.22")

Config.kt

@Configuration
@EnableWebFlux
@EnableReactiveFeignClients
class Config {
}

MyFeignClient.kt

@Component
@ReactiveFeignClient(
        url = "\${package.service.my-service-url}",
        name = "client"
)
interface MyFeignClient {
    @GetMapping(value = ["/my/url?my_param={my_value}"], consumes = ["application/json"])
    fun getValues(
            @PathVariable(name = "my_value") myValue: String?,
        ): Mono<MyEntity?>?
}

Then here goes code in some service class:

val myClient: MyFeignClient = WebReactiveFeign.builder<MyFeignClient>()
        .contract(ReactiveContract(SpringMvcContract()))
        .target(MyFeignClient::class.java, "http://example.com")
// feel free to add .block() to get unpacked value or just chain your logic further
val response = myClient.getValues(param)
like image 82
im_infamous Avatar answered Oct 23 '22 10:10

im_infamous


You can check this library: https://github.com/Playtika/feign-reactive

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

like image 32
yevtsy Avatar answered Oct 23 '22 11:10

yevtsy