@@ -53,6 +53,17 @@ public PublishException(ulong publishSequenceNumber, bool isReturn) : base()
53
53
_publishSequenceNumber = publishSequenceNumber ;
54
54
}
55
55
56
+ public PublishException ( ulong publishSequenceNumber , bool isReturn , string message ) : base ( message )
57
+ {
58
+ if ( publishSequenceNumber == ulong . MinValue )
59
+ {
60
+ throw new ArgumentException ( $ "{ nameof ( publishSequenceNumber ) } must not be 0") ;
61
+ }
62
+
63
+ _isReturn = isReturn ;
64
+ _publishSequenceNumber = publishSequenceNumber ;
65
+ }
66
+
56
67
/// <summary>
57
68
/// <c>true</c> if this exception is due to a <c>basic.return</c>
58
69
/// </summary>
@@ -76,10 +87,10 @@ public class PublishReturnException : PublishException
76
87
private readonly ushort _replyCode ;
77
88
private readonly string _replyText ;
78
89
79
- public PublishReturnException ( ulong publishSequenceNumber ,
90
+ public PublishReturnException ( ulong publishSequenceNumber , string message ,
80
91
string ? exchange = null , string ? routingKey = null ,
81
92
ushort ? replyCode = null , string ? replyText = null )
82
- : base ( publishSequenceNumber , true )
93
+ : base ( publishSequenceNumber , true , message )
83
94
{
84
95
_exchange = exchange ?? string . Empty ;
85
96
_routingKey = routingKey ?? string . Empty ;
@@ -116,11 +127,13 @@ internal static PublishException Create(bool isReturn,
116
127
{
117
128
if ( isReturn )
118
129
{
119
- return new PublishReturnException ( deliveryTag , exchange , routingKey , replyCode , replyText ) ;
130
+ string message = $ "{ replyCode } { replyText } Exchange: { exchange } Routing Key: { routingKey } ";
131
+ return new PublishReturnException ( deliveryTag , message , exchange , routingKey , replyCode , replyText ) ;
120
132
}
121
133
else
122
134
{
123
- return new PublishException ( deliveryTag , isReturn ) ;
135
+ string message = "Message rejected by broker." ;
136
+ return new PublishException ( deliveryTag , isReturn , message ) ;
124
137
}
125
138
}
126
139
}
0 commit comments