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.
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With