You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
670 B
C#

9 months ago
using System.Threading;
namespace POSV.LoadBalance
{
/// <summary>
/// RoundRobin Select
/// </summary>
/// <typeparam name="T"></typeparam>
public class RoundRobinRouting<T> : Routing<T>
{
private int _next;
public RoundRobinRouting()
: this(-1)
{ }
public RoundRobinRouting(int next)
{
_next = next;
}
protected override T selectInternal(object message, T[] instances)
{
var roundNext = Interlocked.Increment(ref _next) & int.MaxValue;
return instances[roundNext % instances.Length];
}
}
}