save checkpoint
This commit is contained in:
@@ -33,8 +33,6 @@ public static class RateLimitServiceCollectionExtensions
|
||||
|
||||
var hasInstanceRules = config.ForInstance?.GetEffectiveRules().Count > 0;
|
||||
var hasEnvironmentRules = HasAnyEnvironmentRules(config.ForEnvironment);
|
||||
if (!hasInstanceRules && !hasEnvironmentRules)
|
||||
return services;
|
||||
|
||||
// Register instance limiter
|
||||
if (hasInstanceRules)
|
||||
@@ -76,7 +74,8 @@ public static class RateLimitServiceCollectionExtensions
|
||||
});
|
||||
}
|
||||
|
||||
// Register rate limit service (orchestrator)
|
||||
// Always register the orchestrator so middleware can run even when no rules are configured.
|
||||
// With no limiters present, the service acts as a no-op allow pass-through.
|
||||
services.AddSingleton(sp =>
|
||||
{
|
||||
var rateLimitConfig = sp.GetRequiredService<RateLimitConfig>();
|
||||
|
||||
@@ -144,7 +144,7 @@ public sealed class RabbitMqTransportClient : ITransportClient, IMicroserviceTra
|
||||
await _channel.QueueBindAsync(
|
||||
queue: _responseQueueName,
|
||||
exchange: _options.ResponseExchange,
|
||||
routingKey: _instanceId,
|
||||
routingKey: _instanceId ?? string.Empty,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public sealed class RabbitMqTransportClient : ITransportClient, IMicroserviceTra
|
||||
await SendToGatewayAsync(helloFrame, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task OnConnectionRecoverySucceededAsync(object sender, EventArgs e)
|
||||
private async Task OnConnectionRecoverySucceededAsync(object sender, AsyncEventArgs e)
|
||||
{
|
||||
_logger.LogInformation("RabbitMQ connection recovered, re-establishing topology and consumer");
|
||||
try
|
||||
|
||||
@@ -147,7 +147,7 @@ public sealed class RabbitMqTransportServer : ITransportServer, IAsyncDisposable
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
private async Task OnConnectionRecoverySucceededAsync(object sender, EventArgs e)
|
||||
private async Task OnConnectionRecoverySucceededAsync(object sender, AsyncEventArgs e)
|
||||
{
|
||||
_logger.LogInformation("RabbitMQ server connection recovered, re-establishing topology and consumer");
|
||||
try
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.Router.Gateway.RateLimit;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Router.Gateway.Tests.RateLimit;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class RateLimitServiceCollectionExtensionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void AddRouterRateLimiting_WithoutRules_RegistersNoOpRateLimitService()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>())
|
||||
.Build();
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
|
||||
services.AddRouterRateLimiting(configuration);
|
||||
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
provider.GetService<RateLimitService>().Should().NotBeNull();
|
||||
provider.GetService<InstanceRateLimiter>().Should().BeNull();
|
||||
provider.GetService<EnvironmentRateLimiter>().Should().BeNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user