Skip to content

Commit 446c4b0

Browse files
committed
Fix bug in the code that did not set certain PublishReturnException data
1 parent 0c564b1 commit 446c4b0

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ private void HandleNack(ulong deliveryTag, bool multiple, bool isReturn,
223223
{
224224
if (_confirmsTaskCompletionSources.Remove(deliveryTag, out TaskCompletionSource<bool>? tcs))
225225
{
226-
PublishException ex = PublishExceptionFactory.Create(isReturn, deliveryTag);
226+
PublishException ex = PublishExceptionFactory.Create(isReturn, deliveryTag,
227+
exchange, routingKey, replyCode, replyText);
227228
tcs.SetException(ex);
228229
}
229230
}

projects/Test/Integration/TestBasicPublishAsync.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
// Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
3030
//---------------------------------------------------------------------------
3131

32+
using System;
3233
using System.Threading.Tasks;
3334
using RabbitMQ.Client;
35+
using RabbitMQ.Client.Exceptions;
3436
using Xunit;
3537
using Xunit.Abstractions;
3638

@@ -49,7 +51,6 @@ public async Task TestQueuePurgeAsync()
4951

5052
var publishSyncSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
5153

52-
5354
QueueDeclareOk q = await _channel.QueueDeclareAsync(string.Empty, false, false, true);
5455

5556
var publishTask = Task.Run(async () =>
@@ -65,5 +66,23 @@ public async Task TestQueuePurgeAsync()
6566
Assert.True(await publishSyncSource.Task);
6667
Assert.Equal((uint)messageCount, await _channel.QueuePurgeAsync(q));
6768
}
69+
70+
[Fact]
71+
public async Task TestBasicReturnAsync()
72+
{
73+
try
74+
{
75+
await _channel.BasicPublishAsync(exchange: string.Empty, routingKey: Guid.NewGuid().ToString(),
76+
mandatory: true, body: GetRandomBody());
77+
}
78+
catch (PublishReturnException prex)
79+
{
80+
Assert.True(prex.IsReturn);
81+
Assert.NotNull(prex.Exchange);
82+
Assert.NotNull(prex.RoutingKey);
83+
Assert.NotEqual(0, prex.ReplyCode);
84+
Assert.NotNull(prex.ReplyText);
85+
}
86+
}
6887
}
6988
}

projects/Test/Integration/TestConcurrentAccessWithSharedChannel.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ await TestConcurrentOperationsAsync(async () =>
145145
}
146146
catch (PublishException ex)
147147
{
148-
if (ex.IsReturn)
148+
if (ex is PublishReturnException prex)
149149
{
150+
Assert.True(prex.IsReturn);
151+
Assert.NotNull(prex.Exchange);
152+
Assert.NotNull(prex.RoutingKey);
153+
Assert.NotEqual(0, prex.ReplyCode);
154+
Assert.NotNull(prex.ReplyText);
150155
Interlocked.Increment(ref totalReturnCount);
151156
}
152157
else

0 commit comments

Comments
 (0)