Skip to content

Commit 1ed4185

Browse files
committed
Restore AbortAsync that takes CancellationTokes so as to not break the API
1 parent 3615d88 commit 1ed4185

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

projects/RabbitMQ.Client/IConnectionExtensions.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
8888
CancellationToken.None);
8989
}
9090

91+
/// <summary>
92+
/// Asynchronously abort this connection and all its channels.
93+
/// </summary>
94+
/// <remarks>
95+
/// Note that all active channels and sessions will be closed if this method is called.
96+
/// In comparison to normal <see cref="CloseAsync(IConnection, CancellationToken)"/> method, <see cref="AbortAsync(IConnection, CancellationToken)"/> will not throw
97+
/// <see cref="IOException"/> during closing connection.
98+
///This method waits infinitely for the in-progress close operation to complete.
99+
/// </remarks>
100+
public static Task AbortAsync(this IConnection connection)
101+
{
102+
return connection.CloseAsync(Constants.ReplySuccess, "Connection close forced",
103+
InternalConstants.DefaultConnectionAbortTimeout, true, default);
104+
}
105+
91106
/// <summary>
92107
/// Asynchronously abort this connection and all its channels.
93108
/// </summary>
@@ -99,8 +114,27 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
99114
/// </remarks>
100115
public static Task AbortAsync(this IConnection connection, CancellationToken cancellationToken = default)
101116
{
102-
return connection.CloseAsync(Constants.ReplySuccess, "Connection close forced", InternalConstants.DefaultConnectionAbortTimeout, true,
103-
cancellationToken);
117+
return connection.CloseAsync(Constants.ReplySuccess, "Connection close forced",
118+
InternalConstants.DefaultConnectionAbortTimeout, true, cancellationToken);
119+
}
120+
121+
/// <summary>
122+
/// Asynchronously abort this connection and all its channels.
123+
/// </summary>
124+
/// <remarks>
125+
/// The method behaves in the same way as <see cref="AbortAsync(IConnection, CancellationToken)"/>, with the only
126+
/// difference that the connection is closed with the given connection close code and message.
127+
/// <para>
128+
/// The close code (See under "Reply Codes" in the AMQP 0-9-1 specification)
129+
/// </para>
130+
/// <para>
131+
/// A message indicating the reason for closing the connection
132+
/// </para>
133+
/// </remarks>
134+
public static Task AbortAsync(this IConnection connection, ushort reasonCode, string reasonText)
135+
{
136+
return connection.CloseAsync(reasonCode, reasonText,
137+
InternalConstants.DefaultConnectionAbortTimeout, true, default);
104138
}
105139

106140
/// <summary>
@@ -118,8 +152,8 @@ public static Task AbortAsync(this IConnection connection, CancellationToken can
118152
/// </remarks>
119153
public static Task AbortAsync(this IConnection connection, ushort reasonCode, string reasonText, CancellationToken cancellationToken = default)
120154
{
121-
return connection.CloseAsync(reasonCode, reasonText, InternalConstants.DefaultConnectionAbortTimeout, true,
122-
cancellationToken);
155+
return connection.CloseAsync(reasonCode, reasonText,
156+
InternalConstants.DefaultConnectionAbortTimeout, true, cancellationToken);
123157
}
124158

125159
/// <summary>

projects/RabbitMQ.Client/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ RabbitMQ.Client.RabbitMQTracingOptions.UsePublisherAsParent.get -> bool
1212
RabbitMQ.Client.RabbitMQTracingOptions.UsePublisherAsParent.set -> void
1313
RabbitMQ.Client.RabbitMQTracingOptions.UseRoutingKeyAsOperationName.get -> bool
1414
RabbitMQ.Client.RabbitMQTracingOptions.UseRoutingKeyAsOperationName.set -> void
15+
static RabbitMQ.Client.IConnectionExtensions.AbortAsync(this RabbitMQ.Client.IConnection! connection) -> System.Threading.Tasks.Task!
16+
static RabbitMQ.Client.IConnectionExtensions.AbortAsync(this RabbitMQ.Client.IConnection! connection, ushort reasonCode, string! reasonText) -> System.Threading.Tasks.Task!
1517
static RabbitMQ.Client.RabbitMQActivitySource.TracingOptions.get -> RabbitMQ.Client.RabbitMQTracingOptions!
1618
static RabbitMQ.Client.RabbitMQActivitySource.TracingOptions.set -> void

0 commit comments

Comments
 (0)