Spring Cloud:如何在不使用Ribbon的情况下使用Feign

24

我想使用Feign而不需要客户端负载均衡器Ribbon,因为我不想运行Eureka,这需要分布式和高可用性。相反,由Route53管理的具有内部DNS名称的内部ELB就可以很好地解决问题。

@FeignClient提供普通URL始终会导致no loadbalancer found for ..,因此我尝试阻止Feign使用Ribbon:

Spring Cloud Netflix附带FeignRibbonClient,如果ribbon-loadbalancer中的ILoadBalancer存在,则会使用它。但是,如果排除了此依赖项,则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 - spencergibb
我刚刚为问题添加了一些上下文:它与Eureka有关。 - Konrad Hosemann
Ribbon不依赖于Eureka。您只需单独告诉负载均衡器远程服务器的位置(例如,创建一个@RibbonClient配置,并将ServerList设置为@Bean)。这并不意味着Spring Cloud中没有可能阻止您轻松完成此操作的错误。 - Dave Syer
新文档:http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-without-eureka - Dave Syer
好的,我没有尝试过那个。但我的观点是,我不想配置服务器列表,我只想使用一个简单的URL,就像使用“RestTemplate”一样。 - Konrad Hosemann
一个简单的URL不就是只有一个元素的列表吗?如果您有功能请求,请放到GitHub上。 - Dave Syer
2个回答

28

如果你想使用纯URL,请使用以下代码:

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

使用Brixton发布系列,您将使用:

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

1
那么URL去哪里了? - Dave Syer
1
更新的答案,放在 value 中。 - spencergibb
3
在Spring Boot 1.3.5版本的Brixton SR1发布中,@FeignClient似乎不再支持loadbalance。有没有其他替代方案? - demaniak
4
感谢 @spencergibb。我也发现我可以通过 ribbon.eureka.enabled=false 来禁用 Ribbon。 - demaniak
2
格林威治版本没有'loadbalance'属性? - Maxi Wu
显示剩余3条评论

5

虽然有些晚了,但是经过调查,如果您提供自己的Client Bean,则不会构建和使用LoadBalancerFeignClient,并且Feign开放跟踪自动配置仍将起作用。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接