Changes: - Remove deprecated Fengling.Activity and YarpGateway.Admin projects - Add points processing services with distributed lock support - Update Vben frontend with gateway management pages - Add gateway config controller and database listener - Update routing to use header-mixed-nav layout - Add comprehensive test suites for Member services - Add YarpGateway integration tests - Update package versions in Directory.Packages.props Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
78 lines
2.3 KiB
C#
78 lines
2.3 KiB
C#
using Microsoft.Extensions.Primitives;
|
|
using Yarp.ReverseProxy.Configuration;
|
|
using YarpGateway.Config;
|
|
|
|
namespace YarpGateway.DynamicProxy;
|
|
|
|
public class DynamicProxyConfigProvider : IProxyConfigProvider
|
|
{
|
|
private volatile IProxyConfig _config;
|
|
private readonly DatabaseRouteConfigProvider _routeProvider;
|
|
private readonly DatabaseClusterConfigProvider _clusterProvider;
|
|
private readonly object _lock = new();
|
|
private CancellationTokenSource? _cts;
|
|
|
|
public DynamicProxyConfigProvider(
|
|
DatabaseRouteConfigProvider routeProvider,
|
|
DatabaseClusterConfigProvider clusterProvider)
|
|
{
|
|
_routeProvider = routeProvider;
|
|
_clusterProvider = clusterProvider;
|
|
_cts = new CancellationTokenSource();
|
|
UpdateConfig();
|
|
}
|
|
|
|
public IProxyConfig GetConfig()
|
|
{
|
|
return _config;
|
|
}
|
|
|
|
public void UpdateConfig()
|
|
{
|
|
lock (_lock)
|
|
{
|
|
_cts?.Cancel();
|
|
_cts = new CancellationTokenSource();
|
|
|
|
var routes = _routeProvider.GetRoutes();
|
|
var clusters = _clusterProvider.GetClusters();
|
|
|
|
_config = new InMemoryProxyConfig(
|
|
routes,
|
|
clusters,
|
|
Array.Empty<IReadOnlyDictionary<string, string>>(),
|
|
_cts.Token
|
|
);
|
|
}
|
|
}
|
|
|
|
public async Task ReloadAsync()
|
|
{
|
|
await _routeProvider.ReloadAsync();
|
|
await _clusterProvider.ReloadAsync();
|
|
UpdateConfig();
|
|
}
|
|
|
|
private class InMemoryProxyConfig : IProxyConfig
|
|
{
|
|
private readonly CancellationChangeToken _changeToken;
|
|
|
|
public InMemoryProxyConfig(
|
|
IReadOnlyList<RouteConfig> routes,
|
|
IReadOnlyList<ClusterConfig> clusters,
|
|
IReadOnlyList<IReadOnlyDictionary<string, string>> transforms,
|
|
CancellationToken token)
|
|
{
|
|
Routes = routes;
|
|
Clusters = clusters;
|
|
Transforms = transforms;
|
|
_changeToken = new CancellationChangeToken(token);
|
|
}
|
|
|
|
public IReadOnlyList<RouteConfig> Routes { get; }
|
|
public IReadOnlyList<ClusterConfig> Clusters { get; }
|
|
public IReadOnlyList<IReadOnlyDictionary<string, string>> Transforms { get; }
|
|
public IChangeToken ChangeToken => _changeToken;
|
|
}
|
|
}
|