迁移 Feign Load Balancer 实现以兼容 Spring cloud 2020.0.0

Posted

技术标签:

【中文标题】迁移 Feign Load Balancer 实现以兼容 Spring cloud 2020.0.0【英文标题】:Migrate Feign Load Balancer implementation to compatible with Spring cloud 2020.0.0 【发布时间】:2021-04-29 05:30:41 【问题描述】:

我有以下 Feign 负载均衡器的实现,它与 spring cloud Hoxtan SR6 依赖项一起工作。

import feign.auth.BasicAuthRequestInterceptor;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.context.annotation.Bean;

public class ClientConfig 

@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor(
        @Value("$username") String username,
        @Value("$password") String password) 
    return new BasicAuthRequestInterceptor(username, password);


@Autowired
private CachingSpringLoadBalancerFactory cachingFactory;
@Autowired
private SpringClientFactory clientFactory;

@Value("$keystore.location")
private String keyStoreLocation;
@Value("$keystore.secPhase")
private String keyPassword;

@Bean
public Client feignClient() 
    SslUtils.KeystoreConfig truststoreConfig = SslUtils.KeystoreConfig.builder().type("JKS").location(keyStoreLocation).password(keyPassword).build();
    SocketFactory factory = new SocketFactory(() -> SslUtils.newContext(null, truststoreConfig));
    NoopHostnameVerifier verifier = new NoopHostnameVerifier();
    Client.Default client = new Client.Default(factory, verifier);
    return new LoadBalancerFeignClient(client, cachingFactory, clientFactory);


我尝试将spring cloud版本升级到2020.0.0。我注意到以下软件包不再可用。

import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;

如何更改当前的实现?或者什么依赖会提供这些包?

【问题讨论】:

添加spring-cloud-starter-loadbalancer。如果仍有问题,请发布您的整个 pom。 【参考方案1】:

我遇到了同样的问题。 最后,我通过添加波纹管依赖解决了错误。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-openfeign-core</artifactId>
    <version>2.2.6.RELEASE</version>
</dependency>

【讨论】:

以上是关于迁移 Feign Load Balancer 实现以兼容 Spring cloud 2020.0.0的主要内容,如果未能解决你的问题,请参考以下文章

使用 Google Cloud Load Balancer 迁移 App Engine 会导致约 1 小时的停机时间

load balancer does not have available server for client: provider

Azure Load Balancer : 简介

Azure Load Balancer 为我们的Web项目提供负载均衡

Load Balancer

在 Kubernetes 集群中使用 MetalLB 作为 Load Balancer(上)