Skip to content

Commit 0320916

Browse files
author
Мальцев Илья Владимирович
committed
Fix unbind queue after recovery connection
1 parent 480c739 commit 0320916

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,13 +946,27 @@ private void PropagateQueueNameChangeToBindings(string oldName, string newName)
946946
{
947947
lock (_recordedEntitiesLock)
948948
{
949+
var recreateEntityList = new List<RecordedBinding>();
949950
foreach (RecordedBinding b in _recordedBindings.Keys)
950951
{
951952
if (b.Destination.Equals(oldName))
952953
{
953-
b.Destination = newName;
954+
recreateEntityList.Add(b);
954955
}
955956
}
957+
958+
foreach (var recordedBinding in recreateEntityList)
959+
{
960+
var newRb = recordedBinding is RecordedQueueBinding
961+
? (RecordedBinding)new RecordedQueueBinding()
962+
: new RecordedExchangeBinding();
963+
newRb.WithArguments(recordedBinding.Arguments)
964+
.WithDestination(newName)
965+
.WithRoutingKey(recordedBinding.RoutingKey)
966+
.WithSource(recordedBinding.Source);
967+
_recordedBindings.Remove(recordedBinding);
968+
_recordedBindings.Add(newRb, 0);
969+
}
956970
}
957971
}
958972

projects/Unit/TestConnectionRecovery.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,35 @@ public void TestServerNamedQueueRecovery()
756756

757757
Model.QueueDeclarePassive(nameAfter);
758758
}
759+
[Test]
760+
public void TestUnbindQueueAfterRecoveryConnection()
761+
{
762+
string q = Model.QueueDeclare("", false, true, true, null).QueueName;
763+
string x = "amq.fanout";
764+
Model.QueueBind(q, x, "");
765+
766+
string nameBefore = q;
767+
string nameAfter = null;
768+
769+
var latch = new ManualResetEventSlim(false);
770+
var connection = (AutorecoveringConnection)Conn;
771+
connection.RecoverySucceeded += (source, ea) => latch.Set();
772+
connection.QueueNameChangeAfterRecovery += (source, ea) => { nameAfter = ea.NameAfter; };
773+
774+
CloseAndWaitForRecovery();
775+
Wait(latch);
776+
777+
Assert.IsNotNull(nameAfter);
778+
Assert.IsTrue(nameBefore.StartsWith("amq."));
779+
Assert.IsTrue(nameAfter.StartsWith("amq."));
780+
Assert.AreNotEqual(nameBefore, nameAfter);
781+
Model.QueueUnbind(nameAfter,x,"");
782+
Model.QueueDeleteNoWait(nameAfter);
783+
latch.Reset();
784+
CloseAndWaitForRecovery();
785+
Wait(latch);
786+
//Model.QueueDeclarePassive(nameAfter);
787+
}
759788

760789
[Test]
761790
public void TestShutdownEventHandlersRecoveryOnConnection()

0 commit comments

Comments
 (0)