提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.env.core.fegin; |
H |
2 |
|
|
3 |
|
|
4 |
import org.springframework.cloud.client.ServiceInstance; |
|
5 |
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties; |
|
6 |
import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer; |
|
7 |
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; |
|
8 |
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; |
|
9 |
|
|
10 |
/** |
|
11 |
* 多环境的 {@link LoadBalancerClientFactory} 实现类 |
|
12 |
* 目的:在创建 {@link ReactiveLoadBalancer} 时,会额外增加 {@link EnvLoadBalancerClient} 代理,用于 tag 过滤服务实例 |
|
13 |
* |
|
14 |
* @author iailab |
|
15 |
*/ |
|
16 |
public class EnvLoadBalancerClientFactory extends LoadBalancerClientFactory { |
|
17 |
|
|
18 |
public EnvLoadBalancerClientFactory(LoadBalancerClientsProperties properties) { |
|
19 |
super(properties); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public ReactiveLoadBalancer<ServiceInstance> getInstance(String serviceId) { |
|
24 |
ReactiveLoadBalancer<ServiceInstance> reactiveLoadBalancer = super.getInstance(serviceId); |
|
25 |
// 参考 {@link com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancerClientConfiguration#nacosLoadBalancer(Environment, LoadBalancerClientFactory, NacosDiscoveryProperties)} 方法 |
|
26 |
return new EnvLoadBalancerClient(super.getLazyProvider(serviceId, ServiceInstanceListSupplier.class), |
|
27 |
serviceId, reactiveLoadBalancer); |
|
28 |
} |
|
29 |
|
|
30 |
} |