Skip to content

Commit 5abd912

Browse files
committed
* Ensure BasicPublishAsync API and extensions use the same parameter order as the 6.x version (cc @danielmarbach)
1 parent fd0f5bd commit 5abd912

22 files changed

+118
-64
lines changed

projects/RabbitMQ.Client/PublicAPI.Shipped.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ RabbitMQ.Client.IChannel.BasicAckAsync(ulong deliveryTag, bool multiple, System.
433433
RabbitMQ.Client.IChannel.BasicAcks -> System.EventHandler<RabbitMQ.Client.Events.BasicAckEventArgs>
434434
RabbitMQ.Client.IChannel.BasicNackAsync(ulong deliveryTag, bool multiple, bool requeue, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
435435
RabbitMQ.Client.IChannel.BasicNacks -> System.EventHandler<RabbitMQ.Client.Events.BasicNackEventArgs>
436-
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(RabbitMQ.Client.CachedString! exchange, RabbitMQ.Client.CachedString! routingKey, TProperties basicProperties, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
437-
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(string! exchange, string! routingKey, TProperties basicProperties, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
438436
RabbitMQ.Client.IChannel.BasicReturn -> System.EventHandler<RabbitMQ.Client.Events.BasicReturnEventArgs>
439437
RabbitMQ.Client.IChannel.CallbackException -> System.EventHandler<RabbitMQ.Client.Events.CallbackExceptionEventArgs>
440438
RabbitMQ.Client.IChannel.ChannelNumber.get -> int
@@ -859,8 +857,6 @@ virtual RabbitMQ.Client.TcpClientAdapter.ReceiveTimeout.set -> void
859857
static RabbitMQ.Client.IChannelExtensions.BasicConsumeAsync(this RabbitMQ.Client.IChannel! channel, string! queue, bool autoAck, RabbitMQ.Client.IAsyncBasicConsumer! consumer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
860858
static RabbitMQ.Client.IChannelExtensions.BasicConsumeAsync(this RabbitMQ.Client.IChannel! channel, string! queue, bool autoAck, string! consumerTag, RabbitMQ.Client.IAsyncBasicConsumer! consumer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
861859
static RabbitMQ.Client.IChannelExtensions.BasicConsumeAsync(this RabbitMQ.Client.IChannel! channel, string! queue, bool autoAck, string! consumerTag, System.Collections.Generic.IDictionary<string!, object?>? arguments, RabbitMQ.Client.IAsyncBasicConsumer! consumer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
862-
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync(this RabbitMQ.Client.IChannel! channel, RabbitMQ.Client.CachedString! exchange, RabbitMQ.Client.CachedString! routingKey, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
863-
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync(this RabbitMQ.Client.IChannel! channel, string! exchange, string! routingKey, System.ReadOnlyMemory<byte> body = default(System.ReadOnlyMemory<byte>), bool mandatory = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
864860
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync<T>(this RabbitMQ.Client.IChannel! channel, RabbitMQ.Client.PublicationAddress! addr, T basicProperties, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
865861
static RabbitMQ.Client.IChannelExtensions.CloseAsync(this RabbitMQ.Client.IChannel! channel, ushort replyCode, string! replyText, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
866862
static RabbitMQ.Client.IChannelExtensions.ExchangeDeclareAsync(this RabbitMQ.Client.IChannel! channel, string! exchange, string! type, bool durable = false, bool autoDelete = false, System.Collections.Generic.IDictionary<string!, object?>? arguments = null, bool noWait = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
@@ -895,4 +891,10 @@ RabbitMQ.Client.ICredentialsProvider.GetCredentialsAsync(System.Threading.Cancel
895891
RabbitMQ.Client.ICredentialsProvider.Name.get -> string!
896892
RabbitMQ.Client.PlainMechanism.HandleChallengeAsync(byte[]? challenge, RabbitMQ.Client.ConnectionConfig! config, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<byte[]!>!
897893
readonly RabbitMQ.Client.ConnectionConfig.CredentialsProvider -> RabbitMQ.Client.ICredentialsProvider!
894+
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(RabbitMQ.Client.CachedString! exchange, RabbitMQ.Client.CachedString! routingKey, bool mandatory, TProperties basicProperties, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
895+
RabbitMQ.Client.IChannel.BasicPublishAsync<TProperties>(string! exchange, string! routingKey, bool mandatory, TProperties basicProperties, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
896+
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync(this RabbitMQ.Client.IChannel! channel, RabbitMQ.Client.CachedString! exchange, RabbitMQ.Client.CachedString! routingKey, bool mandatory, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
897+
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync(this RabbitMQ.Client.IChannel! channel, RabbitMQ.Client.CachedString! exchange, RabbitMQ.Client.CachedString! routingKey, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
898+
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync(this RabbitMQ.Client.IChannel! channel, string! exchange, string! routingKey, bool mandatory, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
899+
static RabbitMQ.Client.IChannelExtensions.BasicPublishAsync(this RabbitMQ.Client.IChannel! channel, string! exchange, string! routingKey, System.ReadOnlyMemory<byte> body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
898900
RabbitMQ.Client.IChannel.ConfirmSelectAsync(bool trackConfirmations = true, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!

projects/RabbitMQ.Client/client/api/IChannel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ Task<string> BasicConsumeAsync(string queue, bool autoAck, string consumerTag, b
198198
/// </summary>
199199
/// <param name="exchange">The exchange.</param>
200200
/// <param name="routingKey">The routing key.</param>
201+
/// <param name="mandatory">If set to <c>true</c>, the message must route to a queue.</param>
201202
/// <param name="basicProperties">The message properties.</param>
202203
/// <param name="body">The message body.</param>
203-
/// <param name="mandatory">If set to <c>true</c>, the message must route to a queue.</param>
204204
/// <param name="cancellationToken">CancellationToken for this operation.</param>
205205
/// <remarks>
206206
/// Routing key must be shorter than 255 bytes.
207207
/// </remarks>
208-
ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, TProperties basicProperties,
209-
ReadOnlyMemory<byte> body = default, bool mandatory = false,
208+
ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey,
209+
bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> body,
210210
CancellationToken cancellationToken = default)
211211
where TProperties : IReadOnlyBasicProperties, IAmqpHeader;
212212

@@ -215,15 +215,15 @@ ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, TPr
215215
/// </summary>
216216
/// <param name="exchange">The exchange.</param>
217217
/// <param name="routingKey">The routing key.</param>
218+
/// <param name="mandatory">If set to <c>true</c>, the message must route to a queue.</param>
218219
/// <param name="basicProperties">The message properties.</param>
219220
/// <param name="body">The message body.</param>
220-
/// <param name="mandatory">If set to <c>true</c>, the message must route to a queue.</param>
221221
/// <param name="cancellationToken">CancellationToken for this operation.</param>
222222
/// <remarks>
223223
/// Routing key must be shorter than 255 bytes.
224224
/// </remarks>
225-
ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, TProperties basicProperties,
226-
ReadOnlyMemory<byte> body = default, bool mandatory = false,
225+
ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey,
226+
bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> body,
227227
CancellationToken cancellationToken = default)
228228
where TProperties : IReadOnlyBasicProperties, IAmqpHeader;
229229

projects/RabbitMQ.Client/client/api/IChannelExtensions.cs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public static Task<string> BasicConsumeAsync(this IChannel channel,
7373
cancellationToken);
7474

7575
/// <summary>
76-
/// (Extension method) Convenience overload of BasicPublish.
76+
/// (Extension method) Convenience overload of <see cref="IChannel.BasicPublishAsync{TProperties}(string, string, bool, TProperties, ReadOnlyMemory{byte}, CancellationToken)"/>
7777
/// </summary>
7878
/// <remarks>
79-
/// The publication occurs with mandatory=false and immediate=false.
79+
/// The publication occurs with mandatory=false.
8080
/// </remarks>
8181
public static ValueTask BasicPublishAsync<T>(this IChannel channel,
8282
PublicationAddress addr,
@@ -85,28 +85,70 @@ public static ValueTask BasicPublishAsync<T>(this IChannel channel,
8585
CancellationToken cancellationToken = default)
8686
where T : IReadOnlyBasicProperties, IAmqpHeader =>
8787
channel.BasicPublishAsync(exchange: addr.ExchangeName, routingKey: addr.RoutingKey,
88-
basicProperties: basicProperties, body: body, mandatory: false,
88+
mandatory: false, basicProperties: basicProperties, body: body,
8989
cancellationToken);
9090

91+
/// <summary>
92+
/// (Extension method) Convenience overload of <see cref="IChannel.BasicPublishAsync{TProperties}(string, string, bool, TProperties, ReadOnlyMemory{byte}, CancellationToken)"/>
93+
/// </summary>
94+
/// <remarks>
95+
/// The publication occurs with mandatory=false and empty BasicProperties
96+
/// </remarks>
9197
public static ValueTask BasicPublishAsync(this IChannel channel,
9298
string exchange,
9399
string routingKey,
94-
ReadOnlyMemory<byte> body = default,
95-
bool mandatory = false,
100+
ReadOnlyMemory<byte> body,
96101
CancellationToken cancellationToken = default) =>
97102
channel.BasicPublishAsync(exchange: exchange, routingKey: routingKey,
98-
basicProperties: EmptyBasicProperty.Empty, body: body, mandatory: mandatory,
103+
mandatory: false, basicProperties: EmptyBasicProperty.Empty, body: body,
99104
cancellationToken);
100105

106+
/// <summary>
107+
/// (Extension method) Convenience overload of <see cref="IChannel.BasicPublishAsync{TProperties}(CachedString, CachedString, bool, TProperties, ReadOnlyMemory{byte}, CancellationToken)" />
108+
/// </summary>
109+
/// <remarks>
110+
/// The publication occurs with mandatory=false and empty BasicProperties
111+
/// </remarks>
101112
public static ValueTask BasicPublishAsync(this IChannel channel,
102113
CachedString exchange,
103114
CachedString routingKey,
104-
ReadOnlyMemory<byte> body = default,
105-
bool mandatory = false,
115+
ReadOnlyMemory<byte> body,
106116
CancellationToken cancellationToken = default) =>
107117
channel.BasicPublishAsync(exchange: exchange, routingKey: routingKey,
108-
basicProperties: EmptyBasicProperty.Empty, body: body, mandatory: mandatory,
109-
cancellationToken);
118+
mandatory: false, basicProperties: EmptyBasicProperty.Empty, body: body,
119+
cancellationToken);
120+
121+
/// <summary>
122+
/// (Extension method) Convenience overload of <see cref="IChannel.BasicPublishAsync{TProperties}(string, string, bool, TProperties, ReadOnlyMemory{byte}, CancellationToken)"/>
123+
/// </summary>
124+
/// <remarks>
125+
/// The publication occurs with empty BasicProperties
126+
/// </remarks>
127+
public static ValueTask BasicPublishAsync(this IChannel channel,
128+
string exchange,
129+
string routingKey,
130+
bool mandatory,
131+
ReadOnlyMemory<byte> body,
132+
CancellationToken cancellationToken = default) =>
133+
channel.BasicPublishAsync(exchange: exchange, routingKey: routingKey,
134+
mandatory: mandatory, basicProperties: EmptyBasicProperty.Empty, body: body,
135+
cancellationToken);
136+
137+
/// <summary>
138+
/// (Extension method) Convenience overload of <see cref="IChannel.BasicPublishAsync{TProperties}(CachedString, CachedString, bool, TProperties, ReadOnlyMemory{byte}, CancellationToken)" />
139+
/// </summary>
140+
/// <remarks>
141+
/// The publication occurs with empty BasicProperties
142+
/// </remarks>
143+
public static ValueTask BasicPublishAsync(this IChannel channel,
144+
CachedString exchange,
145+
CachedString routingKey,
146+
bool mandatory,
147+
ReadOnlyMemory<byte> body,
148+
CancellationToken cancellationToken = default) =>
149+
channel.BasicPublishAsync(exchange: exchange, routingKey: routingKey,
150+
mandatory: mandatory, basicProperties: EmptyBasicProperty.Empty, body: body,
151+
cancellationToken);
110152

111153
/// <summary>
112154
/// Asynchronously declare a queue.

projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,21 @@ await _connection.RecordConsumerAsync(rc, recordedEntitiesSemaphoreHeld: false)
306306
public ValueTask<BasicGetResult?> BasicGetAsync(string queue, bool autoAck, CancellationToken cancellationToken)
307307
=> InnerChannel.BasicGetAsync(queue, autoAck, cancellationToken);
308308

309-
public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, TProperties basicProperties,
310-
ReadOnlyMemory<byte> body, bool mandatory,
311-
CancellationToken cancellationToken)
309+
public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey,
310+
bool mandatory,
311+
TProperties basicProperties,
312+
ReadOnlyMemory<byte> body,
313+
CancellationToken cancellationToken = default)
312314
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
313-
=> InnerChannel.BasicPublishAsync(exchange, routingKey, basicProperties, body, mandatory, cancellationToken);
315+
=> InnerChannel.BasicPublishAsync(exchange, routingKey, mandatory, basicProperties, body, cancellationToken);
314316

315-
public ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, TProperties basicProperties,
316-
ReadOnlyMemory<byte> body, bool mandatory,
317-
CancellationToken cancellationToken)
317+
public ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey,
318+
bool mandatory,
319+
TProperties basicProperties,
320+
ReadOnlyMemory<byte> body,
321+
CancellationToken cancellationToken = default)
318322
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
319-
=> InnerChannel.BasicPublishAsync(exchange, routingKey, basicProperties, body, mandatory, cancellationToken);
323+
=> InnerChannel.BasicPublishAsync(exchange, routingKey, mandatory, basicProperties, body, cancellationToken);
320324

321325
public Task BasicQosAsync(uint prefetchSize, ushort prefetchCount, bool global,
322326
CancellationToken cancellationToken)

projects/RabbitMQ.Client/client/impl/ChannelBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ await ModelSendAsync(method, k.CancellationToken)
925925
}
926926

927927
public async ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey,
928-
TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory,
929-
CancellationToken cancellationToken)
928+
bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> body,
929+
CancellationToken cancellationToken = default)
930930
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
931931
{
932932
if (ConfirmsAreEnabled)
@@ -1004,8 +1004,8 @@ await _confirmSemaphore.WaitAsync(cancellationToken)
10041004
}
10051005

10061006
public async ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey,
1007-
TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory,
1008-
CancellationToken cancellationToken)
1007+
bool mandatory, TProperties basicProperties, ReadOnlyMemory<byte> body,
1008+
CancellationToken cancellationToken = default)
10091009
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
10101010
{
10111011
if (ConfirmsAreEnabled)

projects/Test/Applications/GH-1647/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
{
1919
using var channel = await connection.CreateChannelAsync(); // New channel for each message
2020
await Task.Delay(1000);
21-
await channel.BasicPublishAsync(string.Empty, string.Empty, props, msg);
21+
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: string.Empty,
22+
mandatory: false, basicProperties: props, body: msg);
2223
Console.WriteLine($"Sent message {i}");
2324
}
2425
catch (Exception ex)

projects/Test/Integration/ConnectionRecovery/TestExchangeRecovery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task TestExchangeToExchangeBindingRecovery()
7272
{
7373
await CloseAndWaitForRecoveryAsync();
7474
Assert.True(_channel.IsOpen);
75-
await _channel.BasicPublishAsync(ex_source, "", _encoding.GetBytes("msg"), mandatory: true);
75+
await _channel.BasicPublishAsync(ex_source, "", body: _encoding.GetBytes("msg"), mandatory: true);
7676
await _channel.WaitForConfirmsOrDieAsync();
7777
await AssertMessageCountAsync(q, 1);
7878
}

projects/Test/Integration/ConnectionRecovery/TestRpcAfterRecovery.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public async Task TestPublishRpcRightAfterReconnect()
7777

7878
try
7979
{
80-
await _channel.BasicPublishAsync(string.Empty, testQueueName, properties, _messageBody);
80+
await _channel.BasicPublishAsync(exchange: string.Empty, routingKey: testQueueName,
81+
mandatory: false, basicProperties: properties, body: _messageBody);
8182
}
8283
catch (Exception e)
8384
{

0 commit comments

Comments
 (0)