Skip to content

Commit 79d3e92

Browse files
merge default into bug26097
2 parents 0ff47f1 + a91310f commit 79d3e92

File tree

2 files changed

+83
-8
lines changed

2 files changed

+83
-8
lines changed

projects/client/RabbitMQ.Client/src/client/messagepatterns/Subscription.cs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,13 @@ public void Ack()
175175
}
176176

177177
///<summary>If we are not in "noAck" mode, calls
178-
///IModel.BasicAck with the delivery-tag from the passed in
179-
///event; otherwise, sends nothing to the server. In both
180-
///cases, if the passed-in event is the same as LatestEvent
181-
///(by pointer comparison), sets LatestEvent to
182-
///null.</summary>
178+
///IModel.BasicAck with the delivery-tag from <paramref name="evt"/>;
179+
///otherwise, sends nothing to the server. if <paramref name="evt"/> is the same as LatestEvent
180+
///by pointer comparison, sets LatestEvent to null.
181+
///</summary>
183182
///<remarks>
184-
/// Make sure that this method is only called with events that
185-
/// originated from this Subscription - other usage will have
186-
/// unpredictable results.
183+
///Passing an event that did not originate with this Subscription's
184+
/// channel, will lead to unpredictable behaviour
187185
///</remarks>
188186
public void Ack(BasicDeliverEventArgs evt)
189187
{
@@ -200,6 +198,53 @@ public void Ack(BasicDeliverEventArgs evt)
200198
}
201199
}
202200

201+
///<summary>If LatestEvent is non-null, passes it to
202+
///Nack(BasicDeliverEventArgs, false, requeue). Causes LatestEvent to become
203+
///null.</summary>
204+
public void Nack(bool requeue)
205+
{
206+
if (m_latestEvent != null) {
207+
Nack(m_latestEvent, false, requeue);
208+
}
209+
}
210+
211+
212+
///<summary>If LatestEvent is non-null, passes it to
213+
///Nack(BasicDeliverEventArgs, multiple, requeue). Causes LatestEvent to become
214+
///null.</summary>
215+
public void Nack(bool multiple, bool requeue)
216+
{
217+
if (m_latestEvent != null) {
218+
Nack(m_latestEvent, multiple, requeue);
219+
}
220+
}
221+
222+
///<summary>If we are not in "noAck" mode, calls
223+
///IModel.BasicNack with the delivery-tag from <paramref name="evt"/>;
224+
///otherwise, sends nothing to the server. if <paramref name="evt"/> is the same as LatestEvent
225+
///by pointer comparison, sets LatestEvent to null.
226+
///</summary>
227+
///<remarks>
228+
///Passing an event that did not originate with this Subscription's
229+
/// channel, will lead to unpredictable behaviour
230+
///</remarks>
231+
public void Nack(BasicDeliverEventArgs evt,
232+
bool multiple,
233+
bool requeue)
234+
{
235+
if (evt == null) {
236+
return;
237+
}
238+
239+
if (!m_noAck) {
240+
m_model.BasicNack(evt.DeliveryTag, multiple, requeue);
241+
}
242+
243+
if (evt == m_latestEvent) {
244+
m_latestEvent = null;
245+
}
246+
}
247+
203248
///<summary>Retrieves the next incoming delivery in our
204249
///subscription queue.</summary>
205250
///<remarks>

projects/client/Unit/src/unit/TestMessagePatternsSubscription.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,35 @@ public void TestChannelClosureIsObservableOnSubscription()
7575
BasicDeliverEventArgs r3;
7676
Assert.IsFalse(sub.Next(100, out r3));
7777
}
78+
79+
[Test]
80+
public void TestSubscriptionAck()
81+
{
82+
Model.BasicQos(0, 1, false);
83+
string q = Model.QueueDeclare();
84+
Subscription sub = new Subscription(Model, q, false);
85+
86+
Model.BasicPublish("", q, null, enc.GetBytes("a message"));
87+
BasicDeliverEventArgs res = sub.Next();
88+
Assert.IsNotNull(res);
89+
sub.Ack();
90+
QueueDeclareOk ok = Model.QueueDeclarePassive(q);
91+
Assert.AreEqual(0, ok.MessageCount);
92+
}
93+
94+
[Test]
95+
public void TestSubscriptionNack()
96+
{
97+
Model.BasicQos(0, 1, false);
98+
string q = Model.QueueDeclare();
99+
Subscription sub = new Subscription(Model, q, false);
100+
101+
Model.BasicPublish("", q, null, enc.GetBytes("a message"));
102+
BasicDeliverEventArgs res = sub.Next();
103+
Assert.IsNotNull(res);
104+
sub.Nack(false, false);
105+
QueueDeclareOk ok = Model.QueueDeclarePassive(q);
106+
Assert.AreEqual(0, ok.MessageCount);
107+
}
78108
}
79109
}

0 commit comments

Comments
 (0)