huaweicloud / spring-cloud-huawei

Spring Cloud Huawei is a framework that makes it easier and productive to develop microservices with Spring Cloud.
https://github.com/huaweicloud/spring-cloud-huawei/wiki
Apache License 2.0
520 stars 223 forks source link

open feign define url not work #923

Closed liubao68 closed 2 years ago

liubao68 commented 2 years ago
@FeignClient(name = "urlPrice", url = "http://127.0.0.1:9090")
public interface UrlFeignService {
  @PostMapping("/price")
  String getPrice(@RequestParam("id") Long id);
}
liubao68 commented 2 years ago

This is because open feign hard coded for it's own implementation to use delegate when url is provided: https://github.com/spring-cloud/spring-cloud-openfeign/blob/main/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java

liubao68 commented 2 years ago

work around: do not use feign client governance. set spring.cloud.servicecomb.feign.governance.enabled to false. we'll create a PR for spring-cloud-openfeign to track this problem.

or add a Configuration for non load balanced url,

@FeignClient(name = "urlPrice", url = "http://127.0.0.1:9090",
    configuration = UrlFeignService.Configuration.class)
public interface UrlFeignService {
  @PostMapping("/price")
  String getPrice(@RequestParam("id") Long id);

  class Configuration {
    @Bean
    public Client urlFeignServiceClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient,
        LoadBalancerClientFactory loadBalancerClientFactory) {
      ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
      return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory);
    }
  }
}
liubao68 commented 2 years ago

work around(recommend) : we can treat 3rd-party services like normal discovery services. And we can configure simple discovery client to get the URL. This usable will have all governance features provided by spring cloud huawei.

@FeignClient(name = "urlPrice")
public interface UrlFeignService {
  @PostMapping("/price")
  String getPrice(@RequestParam("id") Long id);
}
spring:
  cloud:
    discovery:
      client:
        simple:
          order: -100 # add order to make this check before others
          instances:
            urlPrice:
              - host: 127.0.0.1
                port: 9090
                instanceId: urlPrice01