Skip to content

Commit

Permalink
Remove synchronous API
Browse files Browse the repository at this point in the history
Part of the fix for #1472

* Remove synchronous API methods
* Update all usages of `CreateConnection` to use `CreateConnectionAsync`
* Ensure that all connections and channels are closed prior to `Dispose`
* Use lowest feasible `LangVersion` for projects
* Add note about nullable reference types in `RabbitMQ.Client.csproj`
* Convert `ManualResetEventSlim` and associated classes to `TaskCompletionSource<bool>` or `SemaphoreSlim`
* Only use `ValueTask` for operations that need the performance benefit
* Add async passive declaration convenience methods to the async API
* Fix missing `CloseAsync` statements prior to disposing `IConnection`
  and `IChannel` instances
* Fix bug where `QueueBindAsync` did not record the binding in an `AutorecoveringChannel`
* Added `ProcessUtil` to run command line executables via `async`
* Make `TopologyRecoveryExceptionHandler` async
* Ensure test classes call `base.DisposeAsync()` appropriately
* Add `RABBITMQ_LONG_RUNNING_TESTS=true` to `build.ps1`
* Remove `Close` and `Abort` from `IConnection` and `IConnectionExtensions`
* Remove `Close` and `Abort` from `IChannel` and `IChannelExtensions`
* Remove use of `RecoveryChannelFactory`
* Remove `Close` from `AutorecoveringConnection` and `Connection`
* Ensure `TestConnectionRecoveryWithoutSetup` tests close and dispose of channels correctly
* Remove `ConfirmSelect`
* Remove `ExchangeBind` and `ExchangeBindNoWait`
* Add `noWait` to `ExchangeBindAsync` and `ExchangeDeclareAsync`
* Remove `ExchangeDeclarePassive`
* Fix stack overflow in `ExchangeBindAsync`
* Remove `ExchangeDelete` and `ExchangeDeleteNoWait`
* Remove `BasicGet`
* Remove `BasicNack`
* Change `BasicNackAsync` to return `ValueTask`
* Remove `BasicCancel` and `BasicCancelNoWait`
* Remove `BasicPublish`
* Remove `BasicQos`
* Remove `BasicReject`
* Remove `ExchangeUnbind` and `ExchangeUnbindNoWait`
* Remove `QueueBind`, `QueueBindNoWait`, QueueDeclare`, `QueueDeclareNoWait`, and `QueueDeclarePassive`
* Remove `QueueDelete` and `QueueDeleteNoWait`
* Make `noWait` the last param in the arg list. Default is `false`
* Remove `BasicAck`
* Modify `IBasicConsumer` to make `HandleBasicDeliver` an async method
* Move `passive` to the end of the argument list, just before `noWait`
* Remove `QueuePurge`
* Remove `QueueUnbind`
* Remove `TxSelect`, `TxCommit` and `TxRollback`
* Remove `WaitForConfirms` and `WaitForConfirmsOrDie`
* Remove `BasicConsume`
* Delete code for sync API
* Make `UpdateSecret` async
  • Loading branch information
lukebakken committed Jan 24, 2024
1 parent f8a3028 commit b65e07e
Show file tree
Hide file tree
Showing 110 changed files with 3,349 additions and 4,250 deletions.
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if ($RunTests)
foreach ($csproj_file in $unit_csproj_file, $integration_csproj_file, $async_integration_csproj_file, $sequential_integration_csproj_file)
{
Write-Host "[INFO] running Unit / Integration tests from '$csproj_file' (all frameworks)" -ForegroundColor "Magenta"
dotnet test $csproj_file --no-restore --no-build --logger "console;verbosity=detailed"
dotnet test $csproj_file --environment 'RABBITMQ_LONG_RUNNING_TESTS=true' --no-restore --no-build --logger "console;verbosity=detailed"
if ($LASTEXITCODE -ne 0)
{
Write-Host "[ERROR] tests errored, exiting" -Foreground "Red"
Expand Down
2 changes: 1 addition & 1 deletion projects/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="Ductus.FluentDocker" Version="2.10.59" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ public AsyncBasicConsumerFake(ManualResetEventSlim autoResetEvent)
return Task.CompletedTask;
}

void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
in ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
Task IBasicConsumer.HandleBasicDeliverAsync(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
{
if (Interlocked.Increment(ref _current) == Count)
{
_current = 0;
_autoResetEvent.Set();
}
return Task.CompletedTask;
}

public Task HandleBasicCancel(string consumerTag) => Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class Networking_BasicDeliver_Commons
public static async Task Publish_Hello_World(IConnection connection, uint messageCount, byte[] body)
{
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
using (var channel = connection.CreateChannel())
using (IChannel channel = await connection.CreateChannelAsync())
{
var queue = channel.QueueDeclare();
var consumed = 0;
QueueDeclareOk queue = await channel.QueueDeclareAsync();
int consumed = 0;
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (s, args) =>
{
Expand All @@ -24,14 +24,15 @@ public static async Task Publish_Hello_World(IConnection connection, uint messag
tcs.SetResult(true);
}
};
channel.BasicConsume(queue.QueueName, true, consumer);
await channel.BasicConsumeAsync(queue.QueueName, true, consumer);

for (int i = 0; i < messageCount; i++)
{
channel.BasicPublish("", queue.QueueName, body);
await channel.BasicPublishAsync("", queue.QueueName, body);
}

await tcs.Task;
await channel.CloseAsync();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void GlobalCleanup()
public async Task Publish_Hello_World()
{
var cf = new ConnectionFactory { ConsumerDispatchConcurrency = 2 };
using (var connection = cf.CreateConnection())
using (IConnection connection = await cf.CreateConnectionAsync())
{
await Publish_Hello_World(connection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public void GlobalSetup()
_container = RabbitMQBroker.Start();

var cf = new ConnectionFactory { ConsumerDispatchConcurrency = 2 };
_connection = cf.CreateConnection();
// TODO / NOTE: https://github.com/dotnet/BenchmarkDotNet/issues/1738
_connection = cf.CreateConnectionAsync().EnsureCompleted();
}

[GlobalCleanup]
Expand Down
13 changes: 6 additions & 7 deletions projects/RabbitMQ.Client.OAuth2/OAuth2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace RabbitMQ.Client.OAuth2
{
public interface IOAuth2Client
{
public IToken RequestToken();
public IToken RefreshToken(IToken token);
IToken RequestToken();
IToken RefreshToken(IToken token);
}

public interface IToken
{
public string AccessToken { get; }
public string RefreshToken { get; }
public TimeSpan ExpiresIn { get; }
public bool hasExpired { get; }
string AccessToken { get; }
string RefreshToken { get; }
TimeSpan ExpiresIn { get; }
bool hasExpired { get; }
}

public class Token : IToken
Expand Down
6 changes: 2 additions & 4 deletions projects/RabbitMQ.Client.OAuth2/RabbitMQ.Client.OAuth2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
<MinVerVerbosity>minimal</MinVerVerbosity>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>../../packages</PackageOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<ReleaseVersion>7.0</ReleaseVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release' And '$(CI)' == 'true'">
Expand Down Expand Up @@ -58,7 +56,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit b65e07e

Please sign in to comment.