Skip to content

Commit cbc8667

Browse files
committed
Use the async disposable channel in the auto recover connection
1 parent 84575d5 commit cbc8667

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,12 @@ private async ValueTask RecoverExchangesAsync(IConnection connection,
299299
{
300300
try
301301
{
302-
using (IChannel ch = await connection.CreateChannelAsync(cancellationToken: cancellationToken).ConfigureAwait(false))
303-
{
304-
await recordedExchange.RecoverAsync(ch, cancellationToken)
305-
.ConfigureAwait(false);
306-
await ch.CloseAsync(cancellationToken)
307-
.ConfigureAwait(false);
308-
}
302+
var channel = await connection.CreateChannelAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
303+
await using var _ = channel.ConfigureAwait(false);
304+
await recordedExchange.RecoverAsync(channel, cancellationToken)
305+
.ConfigureAwait(false);
306+
await channel.CloseAsync(cancellationToken)
307+
.ConfigureAwait(false);
309308
}
310309
catch (Exception ex)
311310
{
@@ -351,11 +350,12 @@ private async Task RecoverQueuesAsync(IConnection connection,
351350
try
352351
{
353352
string newName = string.Empty;
354-
using (IChannel ch = await connection.CreateChannelAsync(cancellationToken: cancellationToken).ConfigureAwait(false))
353+
var channel = await connection.CreateChannelAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
354+
await using (channel.ConfigureAwait(false))
355355
{
356-
newName = await recordedQueue.RecoverAsync(ch, cancellationToken)
356+
newName = await recordedQueue.RecoverAsync(channel, cancellationToken)
357357
.ConfigureAwait(false);
358-
await ch.CloseAsync(cancellationToken)
358+
await channel.CloseAsync(cancellationToken)
359359
.ConfigureAwait(false);
360360
}
361361
string oldName = recordedQueue.Name;
@@ -463,13 +463,12 @@ private async ValueTask RecoverBindingsAsync(IConnection connection,
463463
{
464464
try
465465
{
466-
using (IChannel ch = await connection.CreateChannelAsync(cancellationToken: cancellationToken).ConfigureAwait(false))
467-
{
468-
await binding.RecoverAsync(ch, cancellationToken)
469-
.ConfigureAwait(false);
470-
await ch.CloseAsync(cancellationToken)
471-
.ConfigureAwait(false);
472-
}
466+
var channel = await connection.CreateChannelAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
467+
await using var _ = channel.ConfigureAwait(false);
468+
await binding.RecoverAsync(channel, cancellationToken)
469+
.ConfigureAwait(false);
470+
await channel.CloseAsync(cancellationToken)
471+
.ConfigureAwait(false);
473472
}
474473
catch (Exception ex)
475474
{

0 commit comments

Comments
 (0)