Spring FeignClient:如何配置Ribbon之类的负载均衡器

时间:2019-01-31 19:27:47

标签: java spring spring-boot spring-restcontroller spring-rest

我正在使用Spring FeignClient,并且必须支持Spring Ribbon提供的负载平衡。

@FeignClient(name = "testClient", url = "${test.url}", configuration = TestConfig.class)
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = 
 MediaType.APPLICATION_JSON_VALUE)
 public interface TestClient {
 }

public class TestConfig{
 @Bean
 public Client feignClient() {
    return new ApacheHttpClient(getHttpClient());
  }
}

我想了解如何将Ribbon添加到配置中。

1 个答案:

答案 0 :(得分:1)

可以设置属性,像这样的配置:

hello-service:
  ribbon:
    eureka:
      enabled: false
    listOfServers: localhost:8090,localhost:9092,localhost:9999

没有尤里卡:

stores:
  ribbon:
    listOfServers: example.com,google.com

ribbon docs