Skip to content

Commit a20efc0

Browse files
committed
* Cosmetic formatting
* Use `RateLimitLease` instead of `IDisposable` in internal classes.
1 parent ada1348 commit a20efc0

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,11 @@ internal partial class Channel : IChannel, IRecoverable
5656
private sealed class PublisherConfirmationInfo : IDisposable
5757
{
5858
private TaskCompletionSource<bool>? _publisherConfirmationTcs;
59-
private readonly IDisposable? _lease;
59+
private readonly RateLimitLease? _lease;
6060

61-
internal PublisherConfirmationInfo()
62-
{
63-
PublishSequenceNumber = 0;
64-
_publisherConfirmationTcs = null;
65-
_lease = null;
66-
}
67-
68-
internal PublisherConfirmationInfo(ulong publishSequenceNumber, TaskCompletionSource<bool>? publisherConfirmationTcs, IDisposable? lease)
61+
internal PublisherConfirmationInfo(ulong publishSequenceNumber,
62+
TaskCompletionSource<bool>? publisherConfirmationTcs,
63+
RateLimitLease? lease)
6964
{
7065
PublishSequenceNumber = publishSequenceNumber;
7166
_publisherConfirmationTcs = publisherConfirmationTcs;

projects/RabbitMQ.Client/Impl/ThrottlingRateLimiter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ namespace RabbitMQ.Client.Impl
3838
{
3939
public class ThrottlingRateLimiter : RateLimiter
4040
{
41+
public const int DefaultThrottlingPercentage = 50;
42+
4143
private readonly ConcurrencyLimiter _concurrencyLimiter;
4244
private readonly int _maxConcurrency;
4345
private readonly int _throttlingThreshold;
4446

45-
public ThrottlingRateLimiter(int maxConcurrentCalls, int? throttlingPercentage = 50)
47+
public ThrottlingRateLimiter(int maxConcurrentCalls, int? throttlingPercentage = DefaultThrottlingPercentage)
4648
{
4749
_maxConcurrency = maxConcurrentCalls;
48-
_throttlingThreshold = _maxConcurrency * throttlingPercentage.GetValueOrDefault(50) / 100;
50+
_throttlingThreshold = _maxConcurrency * throttlingPercentage.GetValueOrDefault(DefaultThrottlingPercentage) / 100;
4951

5052
ConcurrencyLimiterOptions limiterOptions = new()
5153
{
@@ -97,7 +99,6 @@ private Task ThrottleIfNeededAsync(CancellationToken cancellationToken = default
9799
}
98100

99101
int delay = (int)((1.0 - availablePermits / (double)_maxConcurrency) * 1000);
100-
101102
return Task.Delay(delay, cancellationToken);
102103
}
103104

projects/RabbitMQ.Client/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const RabbitMQ.Client.Constants.PublishSequenceNumberHeader = "x-dotnet-pub-seq-no" -> string!
2+
const RabbitMQ.Client.Impl.ThrottlingRateLimiter.DefaultThrottlingPercentage = 50 -> int
23
override RabbitMQ.Client.Impl.ThrottlingRateLimiter.AcquireAsyncCore(int permitCount, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<System.Threading.RateLimiting.RateLimitLease!>
34
override RabbitMQ.Client.Impl.ThrottlingRateLimiter.AttemptAcquireCore(int permitCount) -> System.Threading.RateLimiting.RateLimitLease!
45
override RabbitMQ.Client.Impl.ThrottlingRateLimiter.Dispose(bool disposing) -> void

0 commit comments

Comments
 (0)