spring-cloud-openfeign icon indicating copy to clipboard operation
spring-cloud-openfeign copied to clipboard

Create non-blocking `SpringDecoder`.

Open fanticat opened this issue 6 years ago • 10 comments
trafficstars

spring-boot-autoconfigure 2.2.0 change HttpMessageConverters auto configure with condition "NoReativeWebApplicationCondition", so when use openfeign to decode response, there will throws HttpMessageConverters not available exception, could you please add a HttpMessageConverters bean auto configure in openfeign configuration?

fanticat avatar Oct 22 '19 09:10 fanticat

It's happended when I update spring cloud version to Hoxton.RELEASE. And Greenwich.SR4 is ok.

this is ok

<properties>
        <spring.cloud.version>Greenwich.SR4</spring.cloud.version>
        <spring.boot.version>2.1.9.RELEASE</spring.boot.version>
</properties>

this is error

<properties>
        <spring.cloud.version>Hoxton.RELEASE</spring.cloud.version>
        <spring.boot.version>2.2.1.RELEASE</spring.boot.version>
</properties>

feign.codec.DecodeException: No qualifying bean of type 'org.springframework.boot.autoconfigure.http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

lin1005q avatar Dec 02 '19 02:12 lin1005q

I am faced with the same problem with you

I have solved this problem

@Configuration
public class FeignResponseDecoderConfig {
    @Bean
    public Decoder feignDecoder() {

        ObjectFactory<HttpMessageConverters> messageConverters = () -> {
            HttpMessageConverters converters = new HttpMessageConverters();
            return converters;
        };
        return new SpringDecoder(messageConverters);
    }
}

vicliu624 avatar Dec 18 '19 07:12 vicliu624

The above is a workaround. HttpMessageConverter's are blocking and will cause a webflux application to break. HttpMessageReader is the non-blocking equivalent.

spencergibb avatar Jan 13 '20 22:01 spencergibb

@spencergibb can you give some code example? I can't get feign to work even with @vicliu624 code

AlexTo avatar Jan 16 '20 06:01 AlexTo

Ah ok, @vicliu624 code does work but I have to declare both Encoder and Decoder like this

private ObjectFactory<HttpMessageConverters> messageConverters = HttpMessageConverters::new;

    @Bean
    Encoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }

    @Bean
    Decoder feignFormDecoder() {
        return new SpringDecoder(messageConverters);
    }
}

AlexTo avatar Jan 16 '20 06:01 AlexTo

5 months passed. any progress?

rainmanhhh avatar Apr 23 '20 02:04 rainmanhhh

No

spencergibb avatar Apr 23 '20 02:04 spencergibb

Using above workaround would cause performance issue: response time increase from 7ms to 30ms on the same FeignClient request path.

thewaychung avatar Apr 27 '20 03:04 thewaychung

Ah ok, @vicliu624 code does work but I have to declare both Encoder and Decoder like this

private ObjectFactory<HttpMessageConverters> messageConverters = HttpMessageConverters::new;

    @Bean
    Encoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }

    @Bean
    Decoder feignFormDecoder() {
        return new SpringDecoder(messageConverters);
    }
}

I use the following code to solve "feign.codec.EncodeException: ":

private ObjectFactory<HttpMessageConverters> messageConverters = HttpMessageConverters::new;

   /**
    * @return
    */
   @Bean
   Encoder feignEncoder() {
       return new SpringEncoder(messageConverters);
   }

   /**
    * @return
    */
   @Bean
   Decoder feignDecoder() {
       return new SpringDecoder(messageConverters);
   }

Sbwillbealier avatar May 11 '20 01:05 Sbwillbealier

5 months passed. any progress?

I have replaced the openfeign for reactive feign which is not blocking, it's working fine for me.

fanticat avatar Jun 29 '20 01:06 fanticat