From 3bd9d5c2a3195a5ca1121b5889342bca42bad521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Sat, 2 Mar 2024 00:44:33 +0100 Subject: [PATCH] Prepare RTM (#1351) * Prepare RTM * Fix analyzer error * Simplify * Use json * Tweaks * Increase capacity of LRU caches --------- Co-authored-by: Brandon Ording --- .github/workflows/ci.yml | 1 - .github/workflows/release.yml | 3 +- ....Transport.RabbitMQ.AcceptanceTests.csproj | 5 +- ...When_using_a_custom_message_id_strategy.cs | 2 +- ...eBus.Transport.RabbitMQ.CommandLine.csproj | 4 +- ...ServiceBus.Transport.RabbitMQ.Tests.csproj | 5 +- .../RabbitMqContext.cs | 2 +- ...onfigureRabbitMQTransportInfrastructure.cs | 7 +- ...s.Transport.RabbitMQ.TransportTests.csproj | 5 +- src/NServiceBus.Transport.RabbitMQ.sln | 2 + .../RabbitMQTransportSettingsExtensions.cs | 60 +++++++------- src/NServiceBus.Transport.RabbitMQ/Guard.cs | 80 ------------------- .../NServiceBus.Transport.RabbitMQ.csproj | 8 +- .../RabbitMQTransport.cs | 20 ++--- .../Receiving/MessagePump.cs | 4 +- .../NonPersistentDeliveryModeExtensions.cs | 7 +- 16 files changed, 70 insertions(+), 145 deletions(-) delete mode 100644 src/NServiceBus.Transport.RabbitMQ/Guard.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe871399a..337ad5109 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,6 @@ jobs: uses: actions/setup-dotnet@v4.0.0 with: dotnet-version: 8.0.x - dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Upload packages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 266d6a0a0..60a0b61ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,6 @@ jobs: uses: actions/setup-dotnet@v4.0.0 with: dotnet-version: 8.0.x - dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Sign NuGet packages @@ -27,7 +26,7 @@ jobs: client-id: ${{ secrets.AZURE_KEY_VAULT_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_KEY_VAULT_TENANT_ID }} client-secret: ${{ secrets.AZURE_KEY_VAULT_CLIENT_SECRET }} - certificate-name: ${{ secrets.AZURE_KEY_VAULT_CERTIFICATE_NAME }} + certificate-name: ${{ secrets.AZURE_KEY_VAULT_CERTIFICATE_NAME }} - name: Publish artifacts uses: actions/upload-artifact@v4.3.1 with: diff --git a/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/NServiceBus.Transport.RabbitMQ.AcceptanceTests.csproj b/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/NServiceBus.Transport.RabbitMQ.AcceptanceTests.csproj index d5e4df2a9..34683cfc9 100644 --- a/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/NServiceBus.Transport.RabbitMQ.AcceptanceTests.csproj +++ b/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/NServiceBus.Transport.RabbitMQ.AcceptanceTests.csproj @@ -18,8 +18,9 @@ - - + + + diff --git a/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_using_a_custom_message_id_strategy.cs b/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_using_a_custom_message_id_strategy.cs index 7a0d059bc..7af0a88e8 100644 --- a/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_using_a_custom_message_id_strategy.cs +++ b/src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_using_a_custom_message_id_strategy.cs @@ -59,7 +59,7 @@ public Starter(IMessageDispatcher dispatchMessages, IReadOnlySettings settings) protected override Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) { //Use feature to send message that has no message id - var messageBody = ""; + var messageBody = "{}"; var message = new OutgoingMessage( string.Empty, diff --git a/src/NServiceBus.Transport.RabbitMQ.CommandLine/NServiceBus.Transport.RabbitMQ.CommandLine.csproj b/src/NServiceBus.Transport.RabbitMQ.CommandLine/NServiceBus.Transport.RabbitMQ.CommandLine.csproj index 8a64ba1dd..f0336c4b9 100644 --- a/src/NServiceBus.Transport.RabbitMQ.CommandLine/NServiceBus.Transport.RabbitMQ.CommandLine.csproj +++ b/src/NServiceBus.Transport.RabbitMQ.CommandLine/NServiceBus.Transport.RabbitMQ.CommandLine.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/src/NServiceBus.Transport.RabbitMQ.Tests/NServiceBus.Transport.RabbitMQ.Tests.csproj b/src/NServiceBus.Transport.RabbitMQ.Tests/NServiceBus.Transport.RabbitMQ.Tests.csproj index 2665d9fa7..8e7f8a1a9 100644 --- a/src/NServiceBus.Transport.RabbitMQ.Tests/NServiceBus.Transport.RabbitMQ.Tests.csproj +++ b/src/NServiceBus.Transport.RabbitMQ.Tests/NServiceBus.Transport.RabbitMQ.Tests.csproj @@ -18,10 +18,11 @@ - + + - + diff --git a/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs b/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs index 7544d52a2..3da1d3d6f 100644 --- a/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs +++ b/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs @@ -81,7 +81,7 @@ protected IncomingMessage ReceiveMessage() bool TryReceiveMessage(out IncomingMessage message, TimeSpan timeout) => receivedMessages.TryTake(out message, timeout); - protected IList AdditionalReceiverQueues = new List(); + protected IList AdditionalReceiverQueues = []; protected Func OnMessage; protected Func> OnError; diff --git a/src/NServiceBus.Transport.RabbitMQ.TransportTests/ConfigureRabbitMQTransportInfrastructure.cs b/src/NServiceBus.Transport.RabbitMQ.TransportTests/ConfigureRabbitMQTransportInfrastructure.cs index 4455115ea..52c0bd173 100644 --- a/src/NServiceBus.Transport.RabbitMQ.TransportTests/ConfigureRabbitMQTransportInfrastructure.cs +++ b/src/NServiceBus.Transport.RabbitMQ.TransportTests/ConfigureRabbitMQTransportInfrastructure.cs @@ -27,11 +27,12 @@ public async Task Configure(TransportDefinition transpo "mainReceiver", inputQueue, true, - true, errorQueueName); + false, + errorQueueName); - var transport = await transportDefinition.Initialize(hostSettings, new[] { mainReceiverSettings }, new[] { errorQueueName }, cancellationToken); + var transport = await transportDefinition.Initialize(hostSettings, [mainReceiverSettings], [errorQueueName], cancellationToken); - queuesToCleanUp = new[] { transport.ToTransportAddress(inputQueue), errorQueueName }; + queuesToCleanUp = [transport.ToTransportAddress(inputQueue), errorQueueName]; return transport; } diff --git a/src/NServiceBus.Transport.RabbitMQ.TransportTests/NServiceBus.Transport.RabbitMQ.TransportTests.csproj b/src/NServiceBus.Transport.RabbitMQ.TransportTests/NServiceBus.Transport.RabbitMQ.TransportTests.csproj index 72741d5e3..58db00ab0 100644 --- a/src/NServiceBus.Transport.RabbitMQ.TransportTests/NServiceBus.Transport.RabbitMQ.TransportTests.csproj +++ b/src/NServiceBus.Transport.RabbitMQ.TransportTests/NServiceBus.Transport.RabbitMQ.TransportTests.csproj @@ -16,8 +16,9 @@ - - + + + diff --git a/src/NServiceBus.Transport.RabbitMQ.sln b/src/NServiceBus.Transport.RabbitMQ.sln index 7165466f8..0663ae650 100644 --- a/src/NServiceBus.Transport.RabbitMQ.sln +++ b/src/NServiceBus.Transport.RabbitMQ.sln @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.Transport.Rabbi EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CAE42966-8BAA-4BFB-849E-8EE715646607}" ProjectSection(SolutionItems) = preProject + ..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml Custom.Build.props = Custom.Build.props + ..\.github\workflows\release.yml = ..\.github\workflows\release.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Targets", "targets\Targets.csproj", "{F164238E-085A-451A-A852-B06496AE98EB}" diff --git a/src/NServiceBus.Transport.RabbitMQ/Configuration/RabbitMQTransportSettingsExtensions.cs b/src/NServiceBus.Transport.RabbitMQ/Configuration/RabbitMQTransportSettingsExtensions.cs index 62ff923e3..4f1dc4341 100644 --- a/src/NServiceBus.Transport.RabbitMQ/Configuration/RabbitMQTransportSettingsExtensions.cs +++ b/src/NServiceBus.Transport.RabbitMQ/Configuration/RabbitMQTransportSettingsExtensions.cs @@ -19,7 +19,7 @@ public static class RabbitMQTransportSettingsExtensions Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions UseTransport(this EndpointConfiguration config) where T : RabbitMQTransport { - Guard.AgainstNull(nameof(config), config); + ArgumentNullException.ThrowIfNull(config); var transport = new RabbitMQTransport(); @@ -41,7 +41,7 @@ public static TransportExtensions UseTransport(this Endpoi Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions AddClusterNode(this TransportExtensions transportExtensions, string hostName, bool useTls) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.AddClusterNode(hostName, useTls); return transportExtensions; @@ -60,7 +60,7 @@ public static TransportExtensions AddClusterNode(this Transpo Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions AddClusterNode(this TransportExtensions transportExtensions, string hostName, int port, bool useTls) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.AddClusterNode(hostName, port, useTls); return transportExtensions; @@ -74,8 +74,8 @@ public static TransportExtensions AddClusterNode(this Transpo Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions ConnectionString(this TransportExtensions transportExtensions, string connectionString) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNullAndEmpty(nameof(connectionString), connectionString); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentException.ThrowIfNullOrWhiteSpace(connectionString); transportExtensions.Transport.LegacyApiConnectionString = connectionString; return transportExtensions; @@ -89,8 +89,8 @@ public static TransportExtensions ConnectionString(this Trans Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions ConnectionString(this TransportExtensions transportExtensions, Func getConnectionString) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNull(nameof(getConnectionString), getConnectionString); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentNullException.ThrowIfNull(getConnectionString); transportExtensions.Transport.LegacyApiConnectionString = getConnectionString(); return transportExtensions; @@ -107,8 +107,8 @@ public static TransportExtensions ConnectionString(this Trans Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions CustomMessageIdStrategy(this TransportExtensions transportExtensions, Func customIdStrategy) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNull(nameof(customIdStrategy), customIdStrategy); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentNullException.ThrowIfNull(customIdStrategy); transportExtensions.Transport.MessageIdStrategy = customIdStrategy; return transportExtensions; @@ -123,7 +123,7 @@ public static TransportExtensions CustomMessageIdStrategy(thi Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions DisableDurableExchangesAndQueues(this TransportExtensions transportExtensions) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.UseDurableExchangesAndQueues = false; return transportExtensions; @@ -138,7 +138,7 @@ public static TransportExtensions DisableDurableExchangesAndQ Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions DisableRemoteCertificateValidation(this TransportExtensions transportExtensions) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.ValidateRemoteCertificate = false; return transportExtensions; @@ -155,7 +155,7 @@ public static TransportExtensions DisableRemoteCertificateVal Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions PrefetchCount(this TransportExtensions transportExtensions, ushort prefetchCount) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.PrefetchCountCalculation = _ => prefetchCount; return transportExtensions; @@ -172,8 +172,8 @@ public static TransportExtensions PrefetchCount(this Transpor Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions PrefetchMultiplier(this TransportExtensions transportExtensions, int prefetchMultiplier) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNegativeAndZero(nameof(prefetchMultiplier), prefetchMultiplier); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(prefetchMultiplier); transportExtensions.Transport.PrefetchCountCalculation = concurrency => prefetchMultiplier * concurrency; return transportExtensions; @@ -190,8 +190,8 @@ public static TransportExtensions PrefetchMultiplier(this Tra Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions SetClientCertificate(this TransportExtensions transportExtensions, X509Certificate2 clientCertificate) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNull(nameof(clientCertificate), clientCertificate); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentNullException.ThrowIfNull(clientCertificate); transportExtensions.Transport.ClientCertificate = clientCertificate; return transportExtensions; @@ -209,9 +209,9 @@ public static TransportExtensions SetClientCertificate(this T Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions SetClientCertificate(this TransportExtensions transportExtensions, string path, string password) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNullAndEmpty(nameof(path), path); - Guard.AgainstNullAndEmpty(nameof(password), password); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentException.ThrowIfNullOrWhiteSpace(path); + ArgumentException.ThrowIfNullOrWhiteSpace(password); transportExtensions.Transport.ClientCertificate = new X509Certificate2(path, password); return transportExtensions; @@ -228,8 +228,8 @@ public static TransportExtensions SetClientCertificate(this T Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions SetHeartbeatInterval(this TransportExtensions transportExtensions, TimeSpan heartbeatInterval) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNegativeAndZero(nameof(heartbeatInterval), heartbeatInterval); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(heartbeatInterval, TimeSpan.Zero); transportExtensions.Transport.HeartbeatInterval = heartbeatInterval; return transportExtensions; @@ -246,8 +246,8 @@ public static TransportExtensions SetHeartbeatInterval(this T Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions SetNetworkRecoveryInterval(this TransportExtensions transportExtensions, TimeSpan networkRecoveryInterval) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNegativeAndZero(nameof(networkRecoveryInterval), networkRecoveryInterval); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(networkRecoveryInterval, TimeSpan.Zero); transportExtensions.Transport.NetworkRecoveryInterval = networkRecoveryInterval; return transportExtensions; @@ -264,8 +264,8 @@ public static TransportExtensions SetNetworkRecoveryInterval( Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions TimeToWaitBeforeTriggeringCircuitBreaker(this TransportExtensions transportExtensions, TimeSpan waitTime) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNegativeAndZero(nameof(waitTime), waitTime); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(waitTime, TimeSpan.Zero); transportExtensions.Transport.TimeToWaitBeforeTriggeringCircuitBreaker = waitTime; return transportExtensions; @@ -281,7 +281,7 @@ public static TransportExtensions TimeToWaitBeforeTriggeringC Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions UseConventionalRoutingTopology(this TransportExtensions transportExtensions, QueueType queueType) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.TopologyFactory = durable => new ConventionalRoutingTopology(durable, queueType); return transportExtensions; @@ -298,8 +298,8 @@ public static TransportExtensions UseConventionalRoutingTopol Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions UseCustomRoutingTopology(this TransportExtensions transportExtensions, Func topologyFactory) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); - Guard.AgainstNull(nameof(topologyFactory), topologyFactory); + ArgumentNullException.ThrowIfNull(transportExtensions); + ArgumentNullException.ThrowIfNull(topologyFactory); transportExtensions.Transport.TopologyFactory = topologyFactory; return transportExtensions; @@ -317,7 +317,7 @@ public static TransportExtensions UseCustomRoutingTopology(th Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions UseDirectRoutingTopology(this TransportExtensions transportExtensions, QueueType queueType, Func routingKeyConvention = null, Func exchangeNameConvention = null) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.TopologyFactory = durable => new DirectRoutingTopology(durable, queueType, routingKeyConvention, exchangeNameConvention); return transportExtensions; @@ -333,7 +333,7 @@ public static TransportExtensions UseDirectRoutingTopology(th Note = "Should not be converted to an ObsoleteEx until API mismatch described in issue is resolved.")] public static TransportExtensions UseExternalAuthMechanism(this TransportExtensions transportExtensions) { - Guard.AgainstNull(nameof(transportExtensions), transportExtensions); + ArgumentNullException.ThrowIfNull(transportExtensions); transportExtensions.Transport.UseExternalAuthMechanism = true; return transportExtensions; diff --git a/src/NServiceBus.Transport.RabbitMQ/Guard.cs b/src/NServiceBus.Transport.RabbitMQ/Guard.cs deleted file mode 100644 index de7df4b44..000000000 --- a/src/NServiceBus.Transport.RabbitMQ/Guard.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace NServiceBus.Transport.RabbitMQ -{ - using System; - using System.Collections; - using System.Linq; - using System.Reflection; - - static class Guard - { - public static void TypeHasDefaultConstructor(Type type, string argumentName) - { - if (type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) - .All(ctor => ctor.GetParameters().Length != 0)) - { - var error = $"Type '{type.FullName}' must have a default constructor."; - throw new ArgumentException(error, argumentName); - } - } - - public static void AgainstNull(string argumentName, object value) - { - if (value == null) - { - throw new ArgumentNullException(argumentName); - } - } - - public static void AgainstNullAndEmpty(string argumentName, string value) - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentNullException(argumentName); - } - } - - public static void AgainstNullAndEmpty(string argumentName, ICollection value) - { - if (value == null) - { - throw new ArgumentNullException(argumentName); - } - if (value.Count == 0) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegativeAndZero(string argumentName, int value) - { - if (value <= 0) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegative(string argumentName, int value) - { - if (value < 0) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegativeAndZero(string argumentName, TimeSpan value) - { - if (value <= TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - - public static void AgainstNegative(string argumentName, TimeSpan value) - { - if (value < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException(argumentName); - } - } - } -} \ No newline at end of file diff --git a/src/NServiceBus.Transport.RabbitMQ/NServiceBus.Transport.RabbitMQ.csproj b/src/NServiceBus.Transport.RabbitMQ/NServiceBus.Transport.RabbitMQ.csproj index 27507fba5..e0a19ea82 100644 --- a/src/NServiceBus.Transport.RabbitMQ/NServiceBus.Transport.RabbitMQ.csproj +++ b/src/NServiceBus.Transport.RabbitMQ/NServiceBus.Transport.RabbitMQ.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -7,9 +7,9 @@ - - - + + + diff --git a/src/NServiceBus.Transport.RabbitMQ/RabbitMQTransport.cs b/src/NServiceBus.Transport.RabbitMQ/RabbitMQTransport.cs index b6093d680..f9cccc090 100644 --- a/src/NServiceBus.Transport.RabbitMQ/RabbitMQTransport.cs +++ b/src/NServiceBus.Transport.RabbitMQ/RabbitMQTransport.cs @@ -34,8 +34,8 @@ public RabbitMQTransport(RoutingTopology routingTopology, string connectionStrin supportsPublishSubscribe: true, supportsTTBR: true) { - Guard.AgainstNull(nameof(routingTopology), routingTopology); - Guard.AgainstNull(nameof(connectionString), connectionString); + ArgumentNullException.ThrowIfNull(routingTopology); + ArgumentNullException.ThrowIfNull(connectionString); RoutingTopology = routingTopology.Create(); ConnectionConfiguration = ConnectionConfiguration.Create(connectionString); @@ -54,7 +54,7 @@ public Func MessageIdStrategy get => messageIdStrategy; set { - Guard.AgainstNull("value", value); + ArgumentNullException.ThrowIfNull(value); messageIdStrategy = value; } } @@ -67,7 +67,7 @@ public TimeSpan TimeToWaitBeforeTriggeringCircuitBreaker get => timeToWaitBeforeTriggeringCircuitBreaker; set { - Guard.AgainstNegativeAndZero("value", value); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, TimeSpan.Zero); timeToWaitBeforeTriggeringCircuitBreaker = value; } } @@ -80,7 +80,7 @@ public PrefetchCountCalculation PrefetchCountCalculation get => prefetchCountCalculation; set { - Guard.AgainstNull("value", value); + ArgumentNullException.ThrowIfNull(value); prefetchCountCalculation = value; } } @@ -108,7 +108,7 @@ public TimeSpan HeartbeatInterval get => heartbeatInterval; set { - Guard.AgainstNegativeAndZero("value", value); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, TimeSpan.Zero); heartbeatInterval = value; } } @@ -121,7 +121,7 @@ public TimeSpan NetworkRecoveryInterval get => networkRecoveryInterval; set { - Guard.AgainstNegativeAndZero("value", value); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, TimeSpan.Zero); networkRecoveryInterval = value; } } @@ -133,7 +133,7 @@ public TimeSpan NetworkRecoveryInterval /// Indicates if the connection to the node should be secured with TLS. public void AddClusterNode(string hostName, bool useTls) { - Guard.AgainstNullAndEmpty(nameof(hostName), hostName); + ArgumentException.ThrowIfNullOrWhiteSpace(hostName); additionalClusterNodes.Add((hostName, -1, useTls)); } @@ -146,8 +146,8 @@ public void AddClusterNode(string hostName, bool useTls) /// Indicates if the connection to the node should be secured with TLS. public void AddClusterNode(string hostName, int port, bool useTls) { - Guard.AgainstNullAndEmpty(nameof(hostName), hostName); - Guard.AgainstNegativeAndZero(nameof(port), port); + ArgumentException.ThrowIfNullOrWhiteSpace(hostName); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(port); additionalClusterNodes.Add((hostName, port, useTls)); } diff --git a/src/NServiceBus.Transport.RabbitMQ/Receiving/MessagePump.cs b/src/NServiceBus.Transport.RabbitMQ/Receiving/MessagePump.cs index 488ba97c5..9dcf9d89d 100644 --- a/src/NServiceBus.Transport.RabbitMQ/Receiving/MessagePump.cs +++ b/src/NServiceBus.Transport.RabbitMQ/Receiving/MessagePump.cs @@ -28,8 +28,8 @@ sealed class MessagePump : IMessageReceiver readonly Action criticalErrorAction; readonly TimeSpan retryDelay; readonly string name; - readonly FastConcurrentLru deliveryAttempts = new(100); - readonly FastConcurrentLru failedBasicAckMessages = new(100); + readonly FastConcurrentLru deliveryAttempts = new(1_000); + readonly FastConcurrentLru failedBasicAckMessages = new(1_000); OnMessage onMessage; OnError onError; diff --git a/src/NServiceBus.Transport.RabbitMQ/Sending/NonPersistentDeliveryModeExtensions.cs b/src/NServiceBus.Transport.RabbitMQ/Sending/NonPersistentDeliveryModeExtensions.cs index 7161ec28f..22028cc5c 100644 --- a/src/NServiceBus.Transport.RabbitMQ/Sending/NonPersistentDeliveryModeExtensions.cs +++ b/src/NServiceBus.Transport.RabbitMQ/Sending/NonPersistentDeliveryModeExtensions.cs @@ -1,5 +1,6 @@ namespace NServiceBus { + using System; using Transport.RabbitMQ; /// @@ -12,7 +13,7 @@ public static class NonPersistentDeliveryModeExtensions /// public static void UseNonPersistentDeliveryMode(this SendOptions options) { - Guard.AgainstNull(nameof(options), options); + ArgumentNullException.ThrowIfNull(options); options.SetHeader(BasicPropertiesExtensions.UseNonPersistentDeliveryHeader, bool.TrueString); } @@ -22,7 +23,7 @@ public static void UseNonPersistentDeliveryMode(this SendOptions options) /// public static void UseNonPersistentDeliveryMode(this PublishOptions options) { - Guard.AgainstNull(nameof(options), options); + ArgumentNullException.ThrowIfNull(options); options.SetHeader(BasicPropertiesExtensions.UseNonPersistentDeliveryHeader, bool.TrueString); } @@ -32,7 +33,7 @@ public static void UseNonPersistentDeliveryMode(this PublishOptions options) /// public static void UseNonPersistentDeliveryMode(this ReplyOptions options) { - Guard.AgainstNull(nameof(options), options); + ArgumentNullException.ThrowIfNull(options); options.SetHeader(BasicPropertiesExtensions.UseNonPersistentDeliveryHeader, bool.TrueString); }