Skip to content

Commit 1b44924

Browse files
committed
Avoid actually setting unlimited value in policy
1 parent e537c77 commit 1b44924

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/NServiceBus.Transport.RabbitMQ/Administration/BrokerVerifier.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ bool ShouldOverrideDeliveryLimit(Queue queue)
171171

172172
var limit = queue.GetDeliveryLimit();
173173

174-
if (limit == -1)
174+
if (limit is Queue.UnlimitedDeliveryLimitIndicatorValue or BigValueInsteadOfActuallyUnlimited)
175175
{
176176
return false;
177177
}
@@ -201,7 +201,7 @@ async Task SetDeliveryLimitViaPolicy(Queue queue, CancellationToken cancellation
201201
var policy = new Policy
202202
{
203203
ApplyTo = PolicyTarget.QuorumQueues,
204-
Definition = new PolicyDefinition { DeliveryLimit = -1 },
204+
Definition = new PolicyDefinition { DeliveryLimit = BigValueInsteadOfActuallyUnlimited },
205205
Pattern = queue.Name,
206206
Priority = 0
207207
};
@@ -242,4 +242,6 @@ public void Dispose()
242242
Dispose(disposing: true);
243243
GC.SuppressFinalize(this);
244244
}
245+
246+
const int BigValueInsteadOfActuallyUnlimited = 100_000;
245247
}

src/NServiceBus.Transport.RabbitMQ/Administration/ManagementApi/Converters/DeliveryLimitConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSeri
2020

2121
if (string.Equals(value, "unlimited", StringComparison.OrdinalIgnoreCase))
2222
{
23-
return -1;
23+
return Queue.UnlimitedDeliveryLimitIndicatorValue;
2424
}
2525

2626
throw new JsonException($"Unexpected string value for delivery limit: {value}");

src/NServiceBus.Transport.RabbitMQ/Administration/ManagementApi/Models/Queue.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public int GetDeliveryLimit()
6767
limit = 0;
6868
}
6969

70-
return limit ?? -1;
70+
return limit ?? UnlimitedDeliveryLimitIndicatorValue;
7171
}
72+
73+
public const int UnlimitedDeliveryLimitIndicatorValue = -1000;
7274
}

0 commit comments

Comments
 (0)