Search code examples
spring-webfluxproject-reactornetflix-zuulspring-cloud-netflixfeign

Problem deserialize flux/mono into Feign Spring Cloud


i develop a micro services application with Kotlin Webflux (Reactor3), Eureka, Zuul and Feign. Except that I always have an error when I make a call to an API via my micro service Feign. It looks like he can not deserialize the data. Could you please tell me if Feign is compatible with Flux and Monno? thank you

{ "timestamp": "2019-05-29T07:39:43.998+0000", "path": "/hobbies/", "status": 500, "error": "Internal Server Error", "message": "Type definition error: [simple type, class reactor.core.publisher.Flux]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of reactor.core.publisher.Flux (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 1]" }


Solution

  • Feign doesn't provide support for Mono/Flux deserialiazation. There exists alternative feign library who fully support it: feign-reactive.

    Note though, this is a rewrite of feign which fully use reactive code, differ from OpenFeign's Feign core.

    Here's a snippet on how to use it, alongside with normal Feign, taken from the sample app.

    @SpringBootApplication(exclude = ReactiveLoadBalancerAutoConfiguration.class)
    @RestController
    @EnableReactiveFeignClients
    @EnableFeignClients
    public class FeignApplication {
    
        @Autowired
        private GreetingReactive reactiveFeignClient;
    
        @Autowired
        private Greeting feignClient;
    
        public static void main(String[] args) {
            SpringApplication.run(FeignApplication.class, args);
        }
    
        @GetMapping("/greetingReactive")
        public Mono<String> greetingReactive() {
            return reactiveFeignClient.greeting().map(s -> "reactive feign! : " + s);
        }
    
        @GetMapping("/greeting")
        public String greeting() {
            return "feign! : " + feignClient.greeting();
        }
    }