代码之家  ›  专栏  ›  技术社区  ›  JDev

Spring FaignClient:如何配置类似Ribbon的负载平衡器

  •  0
  • JDev  · 技术社区  · 7 年前

    我使用的是SpringFeignClient,必须支持SpringRibbon提供的负载平衡。

    @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());
      }
    }
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   Matt    7 年前

    您可以按如下方式设置配置属性:

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

    没有尤里卡:

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

    ribbon docs