Skip to content

Commit 658e84a

Browse files
author
Emile Joubert
committed
Add eventhandler for RecoverOk
1 parent 9505bdb commit 658e84a

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

projects/client/RabbitMQ.Client/src/client/api/IModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public interface IModel: IDisposable
9393
///</remarks>
9494
event CallbackExceptionEventHandler CallbackException;
9595

96+
///<summary>Signalled when a RecoverOk is received from the
97+
///server. </summary>
98+
event BasicRecoverOkEventHandler BasicRecoverOk;
99+
96100
///<summary>Signalled when an unexpected message is delivered
97101
///
98102
/// Under certain circumstances it is possible for a channel to receive a

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public abstract class ModelBase : IFullModel
8282
private readonly object m_eventLock = new object();
8383
private BasicReturnEventHandler m_basicReturn;
8484
private CallbackExceptionEventHandler m_callbackException;
85+
private BasicRecoverOkEventHandler m_basicRecoverOk;
8586

8687
public ManualResetEvent m_flowControlBlock = new ManualResetEvent(true);
8788

@@ -148,6 +149,24 @@ public event CallbackExceptionEventHandler CallbackException
148149
}
149150
}
150151

152+
public event BasicRecoverOkEventHandler BasicRecoverOk
153+
{
154+
add
155+
{
156+
lock (m_eventLock)
157+
{
158+
m_basicRecoverOk += value;
159+
}
160+
}
161+
remove
162+
{
163+
lock (m_eventLock)
164+
{
165+
m_basicRecoverOk -= value;
166+
}
167+
}
168+
}
169+
151170
public IBasicConsumer DefaultConsumer { get; set; }
152171

153172
public ISession m_session;
@@ -278,6 +297,31 @@ public virtual void OnCallbackException(CallbackExceptionEventArgs args)
278297
}
279298
}
280299
}
300+
301+
public virtual void OnBasicRecoverOk(EventArgs args)
302+
{
303+
BasicRecoverOkEventHandler handler;
304+
lock (m_eventLock)
305+
{
306+
handler = m_basicRecoverOk;
307+
}
308+
if (handler != null)
309+
{
310+
foreach (BasicRecoverOkEventHandler h in handler.GetInvocationList())
311+
{
312+
try
313+
{
314+
h(this, args);
315+
}
316+
catch (Exception e)
317+
{
318+
CallbackExceptionEventArgs exnArgs = new CallbackExceptionEventArgs(e);
319+
exnArgs.Detail["context"] = "OnBasicRecoverOk";
320+
OnCallbackException(exnArgs);
321+
}
322+
}
323+
}
324+
}
281325

282326
public void Enqueue(IRpcContinuation k)
283327
{
@@ -754,6 +798,7 @@ public void BasicRecover(bool requeue)
754798
}
755799

756800
k.GetReply();
801+
OnBasicRecoverOk(new EventArgs());
757802
}
758803

759804
public abstract void BasicQos(uint prefetchSize,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,15 @@ public void TestRecoverAfterCancel_()
115115
Assert.IsFalse(Event.Redelivered);
116116
Assert.IsTrue(Event2.Redelivered);
117117
}
118+
119+
[Test]
120+
public void TestRecoverCallback()
121+
{
122+
int callbackCount = 0;
123+
Channel.BasicRecoverOk += (sender, eventArgs) => callbackCount++;
124+
Channel.BasicRecover(false);
125+
Assert.AreEqual(1, callbackCount);
126+
}
127+
118128
}
119129
}

0 commit comments

Comments
 (0)