feign-reactive icon indicating copy to clipboard operation
feign-reactive copied to clipboard

Add WebFlux WebClient Support

Open SnowZhouJ opened this issue 6 years ago • 17 comments

SnowZhouJ avatar Dec 12 '19 10:12 SnowZhouJ

Would be nice to add a link and some non feign usage examples.

velo avatar Dec 12 '19 19:12 velo

This is the same as the reactive support. WebFlux is Spring's reactive HTTP Client. For now, you can write your own Client to use it, but the request will not be "reactive all the way down". We spoken about this at length about it here: https://github.com/OpenFeign/feign/issues/361 and here: https://github.com/OpenFeign/feign/issues/1120

In short, core Feign will need to be updated to support this.

kdavisk6 avatar Dec 12 '19 19:12 kdavisk6

@kdavisk6 Thank you, I see it. What is the progress now for the reactive support. Can you give me some examples?

SnowZhouJ avatar Dec 13 '19 06:12 SnowZhouJ

@SnowZhouJ Sure. You can find a lot of examples here https://github.com/Playtika/feign-reactive

kptfh avatar Dec 13 '19 07:12 kptfh

@kptfh Are declarative annotations now supported? Like @FeignClient

SnowZhouJ avatar Dec 13 '19 09:12 SnowZhouJ

Yes. Spring auto configuration is fully supported. Check tests for examples. Btw Playtika is using it in prod. Here is the basic sample https://github.com/kptfh/feign-reactive-sample

kptfh avatar Dec 13 '19 09:12 kptfh

@kptfh Application run Failed , Error info: nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class reactivefeign.spring.config.ReactiveFeignClientsConfiguration Is Spring Cloud Version Error ?

SnowZhouJ avatar Dec 13 '19 09:12 SnowZhouJ

Take the last version of https://github.com/Playtika/feign-reactive Now it supports Hoxton and 2.2.2 Spring boot

kptfh avatar Dec 13 '19 09:12 kptfh

I tried to create a new project,Use Hoxton.RELEASE and 2.2.2.RELEASE Spring boot ,But Still failed to start,this is error info Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [reactivefeign.spring.config.ReactiveFeignClientsConfiguration]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class reactivefeign.spring.config.ReactiveFeignClientsConfiguration

SnowZhouJ avatar Dec 13 '19 10:12 SnowZhouJ

@SnowZhouJ Can you update or close this issue as it's already fixed in feign-reactive

kptfh avatar Jan 02 '20 15:01 kptfh

@kptfh

  1. I'm getting an error (Could not autowire. No beans of 'CustomerClient' type found.) in IntellijIdea when using
@ReactiveFeignClient (name="customer-service")
public interface CustomerClient {
    @GetMapping("/service/department/{departmentId}")
    Flux<Customer> findByDepartment(@PathVariable("departmentId") Long departmentId);
}

and injecting it in constructor in another class (Service layer) as:

private CustomerClient customerClient;
@Autowired
public DepartmentService (CustomerClient customerClient) {
        this.customerClient=customerClient;
    }
  1. Does it support fallbackFactory in parameters as it was in OpenFeign. For instance,
@FeignClient(name = "department-service", fallbackFactory = CustomerClientFallbackFactory.class)

if not how can fallback classes be written? *I'm using spring-cloud.version: Hoxton.SR1 and feign-reactor.version: 1.0.44

paro87 avatar Jan 03 '20 21:01 paro87

  1. Annotation @EnableReactiveFeignClients is already included. No changes. The warning still exists.
@SpringBootApplication
@EnableDiscoveryClient
@EnableReactiveFeignClients
@EnableHystrix
public class DepartmentServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(DepartmentServiceApplication.class, args);
    }
}

The warning disappears only when interface is annotated with @ Component annotation.

paro87 avatar Jan 06 '20 11:01 paro87

@paro87 Check this sample project

kptfh avatar Jan 06 '20 11:01 kptfh

@kptfh I encountered with above mentioned bean problem while including FallbackFactory to the parameters as:

@FeignClient(name = "service_statistics", fallbackFactory = StatisticFallbackFactory.class)
public interface ServiceFeignClient {
    @GetMapping("/users/{id}/statistics")
    public List<UserModel> getStatistics(@PathVariable String id);
}

where in OpenFeign FallbackFactory comes from feign.hystrix

import feign.hystrix.FallbackFactory;
@Component
public class StatisticFallbackFactory implements FallbackFactory<ServiceFeignClient> {
    @Override
    public ServiceFeignClient create(Throwable cause) {
        return new ServiceFeignClientFallback(cause);
    }
}

but in Reactive one, it comes from reactivefeign.FallbackFactory. Maybe there is some Hystrix support problem or bean conflict that causes that error. Shortly speaking, "example1" and "example2" (adapted to ReactiveFeign) from this repository https://github.com/ksereda/Spring_Cloud_Netflix_Microservices/tree/master/hystrix works fine, but the problem occurs in "example3".

paro87 avatar Jan 07 '20 08:01 paro87

@paro87 please, create the issue in the reactive feign repo. I would appreciate if you create not working example (you may use fork of the sample project)

kptfh avatar Jan 07 '20 09:01 kptfh

@paro87 Hi paro! I will close this issue, please create new issue in the reactive feign repo( feign-reactive).

SnowZhouJ avatar Jan 08 '20 07:01 SnowZhouJ