public async Task <ILoadBalancer> Get(string serviceName, string loadBalancer = "RoundRobin")
        {
            switch (loadBalancer)
            {
            case "RoundRobin":
                return(new RoundRobin(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName)));

            case "LeastConnection":
                return(new LeastConnection(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            default:
                return(new NoLoadBalancer(await _serviceProvider.FindServiceInstancesAsync(serviceName)));
            }
        }
Exemple #2
0
 /// <summary>
 /// 查询服务发现服务列表
 /// </summary>
 /// <returns></returns>
 public async Task <QueryServiceListOutput> QueryServiceList(QueryServiceListInput input)
 {
     if (string.IsNullOrWhiteSpace(input.Name))
     {
         return(new QueryServiceListOutput {
             Data = await _serviceDiscovery.FindServiceInstancesAsync()
         });
     }
     else
     {
         return(new QueryServiceListOutput {
             Data = await _serviceDiscovery.FindServiceInstancesAsync(input.Name)
         });
     }
 }
 public async Task <BaseOutput <object> > QueryServiceList([FromQuery] QueryServiceListInput input)
 {
     if (input.Name.IsEmpty())
     {
         return(new BaseOutput <object> {
             Data = await _serviceDiscovery.FindServiceInstancesAsync()
         });
     }
     else
     {
         return(new BaseOutput <object> {
             Data = await _serviceDiscovery.FindServiceInstancesAsync(input.Name)
         });
     }
 }
Exemple #4
0
        public async Task <ILoadBalancer> Get(string serviceName, LoadBalancerMode loadBalancer = LoadBalancerMode.RoundRobin)
        {
            switch (loadBalancer)
            {
            case LoadBalancerMode.Random:
                return(new RandomSelector(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            case LoadBalancerMode.RoundRobin:
                return(new RoundRobinSelector(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            case LoadBalancerMode.LeastConnection:
                return(new LeastConnectionSelector(async() => await _serviceProvider.FindServiceInstancesAsync(serviceName), serviceName));

            default:
                return(new NoLoadBalancerSelector(await _serviceProvider.FindServiceInstancesAsync(serviceName)));
            }
        }
        /// <summary>
        /// 查询服务发现服务列表
        /// </summary>
        /// <returns></returns>
        public async Task <QueryServiceListOutput> QueryServiceList(QueryServiceListInput input)
        {
            var result = new object();

            if (input.State == 0)
            {
                result = await _serviceDiscovery.FindAllServicesAsync();
            }
            if (input.State == 1)
            {
                if (string.IsNullOrWhiteSpace(input.Name))
                {
                    result = await _serviceDiscovery.FindServiceInstancesAsync();
                }
                else
                {
                    result = await _serviceDiscovery.FindServiceInstancesAsync(input.Name);
                }
            }
            return(new QueryServiceListOutput {
                Data = result
            });
        }