【问题标题】:Spring Cloud: How to use Feign without RibbonSpring Cloud:如何在没有 Ribbon 的情况下使用 Feign
【发布时间】:2015-02-21 14:15:32
【问题描述】:

我想在没有客户端负载均衡器 Ribbon 的情况下使用 Feign,因为我不想运行 Eureka,它需要分布式和高可用性。相反,具有由 Route53 管理的内部 DNS 名称的内部 ELB 就可以了。

@FeignClient 提供纯 URL 总是会导致 no loadbalancer found for ..,所以我尝试阻止 Feign 使用 Ribbon:

Spring Cloud Netflix 附带FeignRibbonClient,如果存在来自ribbon-loadbalancerILoadBalancer,则使用它。但是,如果排除此依赖关系,FeignConfiguration 将被破坏:

Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiVersionClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: feign.codec.Decoder org.springframework.cloud.netflix.feign.FeignConfiguration.decoder; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

欢迎提出想法 :-)

【问题讨论】:

  • 你为什么不想要ribbon-loadbalancer
  • 我刚刚为这个问题添加了一些上下文:它是关于 Eureka。
  • Ribbon 不依赖于 Eureka。您只需要告诉负载均衡器远程服务器的位置(例如,创建@RibbonClient 配置并将ServerList 设置为@Bean)。这并不是说 Spring Cloud 中可能没有错误阻止您轻松执行此操作。
  • 好吧,我没试过。但我的意思是我不想配置服务器列表,我只想使用纯 URL,就像使用 RestTemplate 一样。

标签: java spring spring-cloud netflix-feign


【解决方案1】:

如果您想使用纯 URL,请使用:

@FeignClient(value = "http://example.com", loadbalance = false)

使用 Brixton 发布火车,您将使用:

@FeignClient(url = "http://example.com", name = "example")

【讨论】:

  • 那么 URL 去哪里了?
  • 更新答案,在value
  • @spencergibb loadbalance@FeignClient 中似乎不再可用(Spring Boot 1.3.5,Brixton SR1 版本)。有其他选择吗?
  • 谢谢@spencergibb。我还发现我可以使用 ribbon.eureka.enabled=false 禁用功能区
  • 格林威治版本没有属性'loadbalance'?
【解决方案2】:

有点晚了,但是在研究了这个之后,如果您提供自己的客户端 Bean,LoadBalancerFeignClient 将不会被构建和使用,并且 Feign 开放跟踪自动配置仍然可以工作。

@Bean
public Client feignClient() {
    return new Client.Default(null, null);
}

【讨论】:

    猜你喜欢
    • 2017-08-27
    • 2016-09-20
    • 2016-02-23
    • 2017-10-07
    • 2021-04-25
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2015-12-12
    相关资源
    最近更新 更多