Search in sources :

Example 1 with LoadBalancer

use of com.alipay.sofa.rpc.client.LoadBalancer in project sofa-rpc by sofastack.

the class AutoLoadBalancer method doSelect.

@Override
protected ProviderInfo doSelect(SofaRequest request, List<ProviderInfo> providerInfos) {
    // 动态配置优先
    final String dynamicAlias = consumerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS);
    if (StringUtils.isNotBlank(dynamicAlias)) {
        String dynamicLoadBalancer = null;
        DynamicConfigManager dynamicConfigManager = DynamicConfigManagerFactory.getDynamicManager(consumerConfig.getAppName(), dynamicAlias);
        if (dynamicConfigManager != null) {
            dynamicLoadBalancer = dynamicConfigManager.getConsumerServiceProperty(request.getTargetServiceUniqueName(), LOAD_BALANCER_KEY);
            if (DynamicHelper.isNotDefault(dynamicLoadBalancer) && StringUtils.isNotBlank(dynamicLoadBalancer)) {
                LoadBalancer loadBalancer = LoadBalancerFactory.getLoadBalancer(consumerBootstrap, dynamicLoadBalancer);
                return loadBalancer.select(request, providerInfos);
            }
        }
    }
    LoadBalancer loadBalancer = LoadBalancerFactory.getLoadBalancer(consumerBootstrap, DEFAULT_LOAD_BALANCER);
    return loadBalancer.select(request, providerInfos);
}
Also used : DynamicConfigManager(com.alipay.sofa.rpc.dynamic.DynamicConfigManager) AbstractLoadBalancer(com.alipay.sofa.rpc.client.AbstractLoadBalancer) LoadBalancer(com.alipay.sofa.rpc.client.LoadBalancer)

Aggregations

AbstractLoadBalancer (com.alipay.sofa.rpc.client.AbstractLoadBalancer)1 LoadBalancer (com.alipay.sofa.rpc.client.LoadBalancer)1 DynamicConfigManager (com.alipay.sofa.rpc.dynamic.DynamicConfigManager)1