36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Microsoft.Extensions.Primitives;
|
|
using System.Threading;
|
|
using Yarp.ReverseProxy.Configuration;
|
|
|
|
namespace YuanXuan.IM.Api.Proxy
|
|
{
|
|
/// <summary>
|
|
/// 代理配置
|
|
/// </summary>
|
|
public class ProxyConfig : IProxyConfig
|
|
{
|
|
private static CancellationTokenSource _cts = new CancellationTokenSource();
|
|
|
|
public ProxyConfig(IReadOnlyList<RouteConfig> routes, IReadOnlyList<ClusterConfig> clusters, DateTime timestamp)
|
|
{
|
|
Routes = routes;
|
|
Clusters = clusters;
|
|
Timestamp = timestamp;
|
|
}
|
|
|
|
public IReadOnlyList<RouteConfig> Routes { get; }
|
|
public IReadOnlyList<ClusterConfig> Clusters { get; }
|
|
public DateTime Timestamp { get; }
|
|
public IChangeToken ChangeToken => new CancellationChangeToken(_cts.Token);
|
|
|
|
/// <summary>
|
|
/// 通知配置变更
|
|
/// </summary>
|
|
public static void SignalChange()
|
|
{
|
|
var oldCts = Interlocked.Exchange(ref _cts, new CancellationTokenSource());
|
|
oldCts.Cancel();
|
|
}
|
|
}
|
|
}
|