Skip to content

Commit

Permalink
switch to NRT for the whole client
Browse files Browse the repository at this point in the history
  • Loading branch information
bollhals committed Jul 3, 2024
1 parent 56b3ebf commit b65ca0d
Show file tree
Hide file tree
Showing 96 changed files with 605 additions and 677 deletions.
2 changes: 1 addition & 1 deletion projects/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageVersion Include="Ductus.FluentDocker" Version="2.10.59" />
<PackageVersion Include="EasyNetQ.Management.Client" Version="2.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Nullable" Version="1.3.1" />
<PackageVersion Include="OpenTelemetry.Api" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Exporter.InMemory" Version="1.8.0" />
<!--
Expand Down Expand Up @@ -41,7 +42,6 @@
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>
<ItemGroup Condition="'$(IsPackable)'=='true'">
<GlobalPackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="MinVer" Version="5.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

namespace RabbitMQ
{
#nullable enable
#if NETSTANDARD
internal static class DictionaryExtension
{
Expand Down
4 changes: 3 additions & 1 deletion projects/RabbitMQ.Client/RabbitMQ.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
https://devblogs.microsoft.com/dotnet/embracing-nullable-reference-types/#what-should-library-authors-do
Note: only setting language version 8.0 for nullable reference types!
-->
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release' And '$(CI)' == 'true'">
Expand Down Expand Up @@ -64,6 +65,7 @@
See https://github.com/rabbitmq/rabbitmq-dotnet-client/pull/1481#pullrequestreview-1847905299
-->
<PackageReference Include="System.IO.Pipelines" />
<PackageReference Include="Nullable" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/api/AmqpTcpEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static AmqpTcpEndpoint[] ParseMultiple(string addresses)
/// <summary>
/// Compares this instance by value (protocol, hostname, port) against another instance.
/// </summary>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (!(obj is AmqpTcpEndpoint other))
{
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/api/AmqpTimestamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public AmqpTimestamp(long unixTime) : this()

public bool Equals(AmqpTimestamp other) => UnixTime == other.UnixTime;

public override bool Equals(object obj) => obj is AmqpTimestamp other && Equals(other);
public override bool Equals(object? obj) => obj is AmqpTimestamp other && Equals(other);

public override int GetHashCode() => UnixTime.GetHashCode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string[] ConsumerTags
/// If our <see cref="IChannel"/> shuts down, this property will contain a description of the reason for the
/// shutdown. Otherwise it will contain null. See <see cref="ShutdownEventArgs"/>.
/// </summary>
public ShutdownEventArgs ShutdownReason { get; protected set; }
public ShutdownEventArgs? ShutdownReason { get; protected set; }

/// <summary>
/// Signalled when the consumer gets cancelled.
Expand All @@ -64,7 +64,7 @@ public event AsyncEventHandler<ConsumerEventArgs> ConsumerCancelled
/// Retrieve the <see cref="IChannel"/> this consumer is associated with,
/// for use in acknowledging received messages, for instance.
/// </summary>
public IChannel Channel { get; set; }
public IChannel? Channel { get; set; }

/// <summary>
/// Called when the consumer is cancelled for reasons other than by a basicCancel:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BasicCredentialsProvider : ICredentialsProvider
private readonly string _userName;
private readonly string _password;

public BasicCredentialsProvider(string name, string userName, string password)
public BasicCredentialsProvider(string? name, string userName, string password)
{
_name = name ?? string.Empty;
_userName = userName ?? throw new ArgumentNullException(nameof(userName));
Expand Down
17 changes: 14 additions & 3 deletions projects/RabbitMQ.Client/client/api/BasicProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using RabbitMQ.Client.Framing.Impl;
using RabbitMQ.Client.Impl;

namespace RabbitMQ.Client
{
#nullable enable
/// <summary>
/// AMQP specification content header properties for content class "basic".
/// </summary>
Expand Down Expand Up @@ -74,7 +74,7 @@ public PublicationAddress? ReplyToAddress
{
get
{
PublicationAddress.TryParse(ReplyTo, out PublicationAddress result);
PublicationAddress.TryParse(ReplyTo, out PublicationAddress? result);
return result;
}

Expand All @@ -85,7 +85,7 @@ public BasicProperties()
{
}

public BasicProperties(ReadOnlyBasicProperties input)
public BasicProperties(IReadOnlyBasicProperties input)
{
ContentType = input.ContentType;
ContentEncoding = input.ContentEncoding;
Expand Down Expand Up @@ -118,19 +118,30 @@ public BasicProperties(ReadOnlyBasicProperties input)
public void ClearAppId() => AppId = default;
public void ClearClusterId() => ClusterId = default;

[MemberNotNullWhen(true, nameof(ContentType))]
public bool IsContentTypePresent() => ContentType != default;
[MemberNotNullWhen(true, nameof(ContentEncoding))]
public bool IsContentEncodingPresent() => ContentEncoding != default;
[MemberNotNullWhen(true, nameof(Headers))]
public bool IsHeadersPresent() => Headers != default;
public bool IsDeliveryModePresent() => DeliveryMode != default;
public bool IsPriorityPresent() => Priority != default;
[MemberNotNullWhen(true, nameof(CorrelationId))]
public bool IsCorrelationIdPresent() => CorrelationId != default;
[MemberNotNullWhen(true, nameof(ReplyTo))]
public bool IsReplyToPresent() => ReplyTo != default;
[MemberNotNullWhen(true, nameof(Expiration))]
public bool IsExpirationPresent() => Expiration != default;
[MemberNotNullWhen(true, nameof(MessageId))]
public bool IsMessageIdPresent() => MessageId != default;
public bool IsTimestampPresent() => Timestamp != default;
[MemberNotNullWhen(true, nameof(Type))]
public bool IsTypePresent() => Type != default;
[MemberNotNullWhen(true, nameof(UserId))]
public bool IsUserIdPresent() => UserId != default;
[MemberNotNullWhen(true, nameof(AppId))]
public bool IsAppIdPresent() => AppId != default;
[MemberNotNullWhen(true, nameof(ClusterId))]
public bool IsClusterIdPresent() => ClusterId != default;

ushort IAmqpHeader.ProtocolClassId => ClassConstants.Basic;
Expand Down
6 changes: 4 additions & 2 deletions projects/RabbitMQ.Client/client/api/BinaryTableValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
//---------------------------------------------------------------------------

using System;

namespace RabbitMQ.Client
{
/// <summary>Wrapper for a byte[]. May appear as values read from
Expand Down Expand Up @@ -61,9 +63,9 @@ namespace RabbitMQ.Client
public class BinaryTableValue
{
/// <summary>
/// Creates a new instance of the <see cref="BinaryTableValue"/> with null for its Bytes property.
/// Creates a new instance of the <see cref="BinaryTableValue"/> with an empty array for its Bytes property.
/// </summary>
public BinaryTableValue() : this(null)
public BinaryTableValue() : this(Array.Empty<byte>())
{
}

Expand Down
3 changes: 1 addition & 2 deletions projects/RabbitMQ.Client/client/api/ConnectionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

namespace RabbitMQ.Client
{
#nullable enable
/// <summary>
/// The configuration of a connection.
/// </summary>
Expand Down Expand Up @@ -151,7 +150,7 @@ public sealed class ConnectionConfig
internal readonly Func<AmqpTcpEndpoint, CancellationToken, Task<IFrameHandler>> FrameHandlerFactoryAsync;

internal ConnectionConfig(string virtualHost, string userName, string password,
ICredentialsProvider credentialsProvider, ICredentialsRefresher credentialsRefresher,
ICredentialsProvider? credentialsProvider, ICredentialsRefresher credentialsRefresher,
IEnumerable<IAuthMechanismFactory> authMechanisms,
IDictionary<string, object?> clientProperties, string? clientProvidedName,
ushort maxChannelCount, uint maxFrameSize, uint maxInboundMessageBodySize, bool topologyRecoveryEnabled,
Expand Down
53 changes: 28 additions & 25 deletions projects/RabbitMQ.Client/client/api/ConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Linq;
using System.Net.Security;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Authentication;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -107,7 +108,7 @@ public sealed class ConnectionFactory : ConnectionFactoryBase, IConnectionFactor
public const uint DefaultFrameMax = 0;

/// <summary>
/// Default value for <code>ConnectionFactory</code>'s <code>MaxInboundMessageBodySize</code>.
/// Default value for <code>ConnectionFactory</code>'s <code>MaxInboundMessageBodySize</code>.
/// </summary>
public const uint DefaultMaxInboundMessageBodySize = 1_048_576 * 64;

Expand Down Expand Up @@ -196,8 +197,8 @@ public sealed class ConnectionFactory : ConnectionFactoryBase, IConnectionFactor
private TimeSpan _continuationTimeout = TimeSpan.FromSeconds(20);

// just here to hold the value that was set through the setter
private Uri _uri;
private string _clientProvidedName;
private Uri? _uri;
private string? _clientProvidedName;

/// <summary>
/// Amount of time protocol handshake operations are allowed to take before
Expand Down Expand Up @@ -278,7 +279,7 @@ public TimeSpan ContinuationTimeout
/// </summary>
public ConnectionFactory()
{
ClientProperties = new Dictionary<string, object>(DefaultClientProperties);
ClientProperties = new Dictionary<string, object?>(DefaultClientProperties);
}

/// <summary>
Expand All @@ -299,12 +300,12 @@ public AmqpTcpEndpoint Endpoint
/// <summary>
/// Dictionary of client properties to be sent to the server.
/// </summary>
public IDictionary<string, object> ClientProperties { get; set; }
public IDictionary<string, object?> ClientProperties { get; set; }

private static readonly Dictionary<string, object> DefaultClientProperties = new Dictionary<string, object>(5)
private static readonly Dictionary<string, object?> DefaultClientProperties = new Dictionary<string, object?>(5)
{
["product"] = Encoding.UTF8.GetBytes("RabbitMQ"),
["version"] = Encoding.UTF8.GetBytes(typeof(ConnectionFactory).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion),
["version"] = Encoding.UTF8.GetBytes(typeof(ConnectionFactory).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion),
["platform"] = Encoding.UTF8.GetBytes(".NET"),
["copyright"] = Encoding.UTF8.GetBytes("Copyright (c) 2007-2023 Broadcom."),
["information"] = Encoding.UTF8.GetBytes("Licensed under the MPL. See https://www.rabbitmq.com/")
Expand All @@ -323,7 +324,7 @@ public AmqpTcpEndpoint Endpoint
/// <summary>
/// CredentialsProvider used to obtain username and password.
/// </summary>
public ICredentialsProvider CredentialsProvider { get; set; }
public ICredentialsProvider? CredentialsProvider { get; set; }

/// <summary>
/// Used to refresh credentials.
Expand Down Expand Up @@ -359,7 +360,7 @@ public AmqpTcpEndpoint Endpoint
/// <summary>
/// The uri to use for the connection.
/// </summary>
public Uri Uri
public Uri? Uri
{
get { return _uri; }
set { SetUri(value); }
Expand All @@ -368,7 +369,7 @@ public Uri Uri
/// <summary>
/// Default client provided name to be used for connections.
/// </summary>
public string ClientProvidedName
public string? ClientProvidedName
{
get => _clientProvidedName;
set
Expand All @@ -381,7 +382,7 @@ public string ClientProvidedName
/// Given a list of mechanism names supported by the server, select a preferred mechanism,
/// or null if we have none in common.
/// </summary>
public IAuthMechanismFactory AuthMechanismFactory(IEnumerable<string> argServerMechanismNames)
public IAuthMechanismFactory? AuthMechanismFactory(IEnumerable<string> argServerMechanismNames)
{
string[] serverMechanismNames = argServerMechanismNames.ToArray();

Expand Down Expand Up @@ -435,7 +436,7 @@ public Task<IConnection> CreateConnectionAsync(
/// <exception cref="BrokerUnreachableException">
/// When the configured hostname was not reachable.
/// </exception>
public Task<IConnection> CreateConnectionAsync(string clientProvidedName,
public Task<IConnection> CreateConnectionAsync(string? clientProvidedName,
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(EndpointResolverFactory(LocalEndpoints()), clientProvidedName, cancellationToken);
Expand Down Expand Up @@ -483,7 +484,7 @@ public Task<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames,
/// <exception cref="BrokerUnreachableException">
/// When no hostname was reachable.
/// </exception>
public Task<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, string clientProvidedName,
public Task<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, string? clientProvidedName,
CancellationToken cancellationToken = default)
{
IEnumerable<AmqpTcpEndpoint> endpoints = hostnames.Select(h => new AmqpTcpEndpoint(h, Port, Ssl, MaxInboundMessageBodySize));
Expand Down Expand Up @@ -530,7 +531,7 @@ public Task<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endp
/// <exception cref="BrokerUnreachableException">
/// When no hostname was reachable.
/// </exception>
public Task<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, string clientProvidedName,
public Task<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, string? clientProvidedName,
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(EndpointResolverFactory(endpoints), clientProvidedName, cancellationToken);
Expand All @@ -553,17 +554,15 @@ public Task<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endp
/// <exception cref="BrokerUnreachableException">
/// When no hostname was reachable.
/// </exception>
public async Task<IConnection> CreateConnectionAsync(IEndpointResolver endpointResolver, string clientProvidedName,
public async Task<IConnection> CreateConnectionAsync(IEndpointResolver endpointResolver, string? clientProvidedName,
CancellationToken cancellationToken = default)
{
ConnectionConfig config = CreateConfig(clientProvidedName);
try
{
if (AutomaticRecoveryEnabled)
{
var c = new AutorecoveringConnection(config, endpointResolver);
return await c.OpenAsync(cancellationToken)
.ConfigureAwait(false);
return await AutorecoveringConnection.CreateAsync(config, endpointResolver, cancellationToken).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -591,7 +590,7 @@ public async Task<IConnection> CreateConnectionAsync(IEndpointResolver endpointR
}
}

private ConnectionConfig CreateConfig(string clientProvidedName)
private ConnectionConfig CreateConfig(string? clientProvidedName)
{
return new ConnectionConfig(
VirtualHost,
Expand Down Expand Up @@ -622,10 +621,8 @@ internal async Task<IFrameHandler> CreateFrameHandlerAsync(
AmqpTcpEndpoint endpoint, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
IFrameHandler fh = new SocketFrameHandler(endpoint, SocketFactory, RequestedConnectionTimeout, SocketReadTimeout, SocketWriteTimeout);
await fh.ConnectAsync(cancellationToken)
.ConfigureAwait(false);
return ConfigureFrameHandler(fh);
SocketFrameHandler frameHandler = await SocketFrameHandler.CreateAsync(endpoint, SocketFactory, RequestedConnectionTimeout, cancellationToken).ConfigureAwait(false);
return ConfigureFrameHandler(frameHandler);
}

private IFrameHandler ConfigureFrameHandler(IFrameHandler fh)
Expand All @@ -647,8 +644,14 @@ private IFrameHandler ConfigureFrameHandler(IFrameHandler fh)
return fh;
}

private void SetUri(Uri uri)
private void SetUri(Uri? uri)
{
if (uri is null)
{
_uri = uri;
return;
}

Endpoint = new AmqpTcpEndpoint();

if (string.Equals("amqp", uri.Scheme, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -721,7 +724,7 @@ private List<AmqpTcpEndpoint> LocalEndpoints()
return new List<AmqpTcpEndpoint> { Endpoint };
}

private static string EnsureClientProvidedNameLength(string clientProvidedName)
private static string? EnsureClientProvidedNameLength(string? clientProvidedName)
{
if (clientProvidedName != null)
{
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/client/api/DefaultBasicConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public string[] ConsumerTags
/// If our <see cref="IChannel"/> shuts down, this property will contain a description of the reason for the
/// shutdown. Otherwise it will contain null. See <see cref="ShutdownEventArgs"/>.
/// </summary>
public ShutdownEventArgs ShutdownReason { get; protected set; }
public ShutdownEventArgs? ShutdownReason { get; protected set; }

/// <summary>
/// Signalled when the consumer gets cancelled.
Expand All @@ -106,7 +106,7 @@ public event EventHandler<ConsumerEventArgs> ConsumerCancelled
/// Retrieve the <see cref="IChannel"/> this consumer is associated with,
/// for use in acknowledging received messages, for instance.
/// </summary>
public IChannel Channel { get; set; }
public IChannel? Channel { get; set; }

/// <summary>
/// Called when the consumer is cancelled for reasons other than by a basicCancel:
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/api/ExternalMechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExternalMechanism : IAuthMechanism
/// <summary>
/// Handle one round of challenge-response.
/// </summary>
public byte[] handleChallenge(byte[] challenge, ConnectionConfig config)
public byte[] handleChallenge(byte[]? challenge, ConnectionConfig config)
{
return Array.Empty<byte>();
}
Expand Down
Loading

0 comments on commit b65ca0d

Please sign in to comment.