2021-10-10 17:30:31 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using Consul;
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-10-12 16:52:28 +08:00
|
|
|
|
using Yi.Framework.Common.IOCOptions;
|
2021-10-10 17:30:31 +08:00
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
namespace Yi.Framework.Core.ConsulExtend
|
2021-10-10 17:30:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 平均
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class AverageDispatcher : AbstractConsulDispatcher
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Identity
|
|
|
|
|
|
private static int _iTotalCount = 0;
|
|
|
|
|
|
private static int iTotalCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _iTotalCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_iTotalCount = value >= Int32.MaxValue ? 0 : value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AverageDispatcher(IOptionsMonitor<ConsulClientOption> consulClientOption) : base(consulClientOption)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 平均
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
protected override int GetIndex()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Random(iTotalCount++).Next(0, base._CurrentAgentServiceDictionary.Length);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|