@@ -882,5 +882,64 @@ public void TestUnblockedListenersRecovery()
882882 Unblock ( ) ;
883883 Wait ( latch , "connection unblocked" ) ;
884884 }
885+
886+ [ Fact ]
887+ public void TestBindingRecovery_GH1035 ( )
888+ {
889+ const string routingKey = "unused" ;
890+ byte [ ] body = GetRandomBody ( ) ;
891+
892+ using var receivedMessageEvent = new AutoResetEvent ( initialState : false ) ;
893+
894+ void MessageReceived ( object sender , BasicDeliverEventArgs e )
895+ {
896+ receivedMessageEvent . Set ( ) ;
897+ }
898+
899+ string exchangeName = $ "ex-gh-1035-{ Guid . NewGuid ( ) } ";
900+ string queueName = $ "q-gh-1035-{ Guid . NewGuid ( ) } ";
901+
902+ _channel . ExchangeDeclare ( exchange : exchangeName ,
903+ type : "fanout" , durable : false , autoDelete : true ,
904+ arguments : null ) ;
905+
906+ RabbitMQ . Client . QueueDeclareOk q0 = _channel . QueueDeclare ( queue : queueName , exclusive : true ) ;
907+ Assert . Equal ( queueName , q0 ) ;
908+
909+ _channel . QueueBind ( queue : queueName , exchange : exchangeName , routingKey : routingKey ) ;
910+
911+ _channel . Dispose ( ) ;
912+
913+ _channel = _conn . CreateChannel ( ) ;
914+
915+ _channel . ExchangeDeclare ( exchange : exchangeName ,
916+ type : "fanout" , durable : false , autoDelete : true ,
917+ arguments : null ) ;
918+
919+ RabbitMQ . Client . QueueDeclareOk q1 = _channel . QueueDeclare ( queue : queueName , exclusive : true ) ;
920+ Assert . Equal ( queueName , q1 . QueueName ) ;
921+
922+ _channel . QueueBind ( queue : queueName , exchange : exchangeName , routingKey : routingKey ) ;
923+
924+ var c = new EventingBasicConsumer ( _channel ) ;
925+ c . Received += MessageReceived ;
926+ _channel . BasicConsume ( queue : queueName , autoAck : true , consumer : c ) ;
927+
928+ using ( IChannel pubCh = _conn . CreateChannel ( ) )
929+ {
930+ pubCh . BasicPublish ( exchange : exchangeName , routingKey : routingKey , body : body ) ;
931+ }
932+
933+ Assert . True ( receivedMessageEvent . WaitOne ( WaitSpan ) ) ;
934+
935+ CloseAndWaitForRecovery ( ) ;
936+
937+ using ( IChannel pubCh = _conn . CreateChannel ( ) )
938+ {
939+ pubCh . BasicPublish ( exchange : exchangeName , routingKey : "unused" , body : body ) ;
940+ }
941+
942+ Assert . True ( receivedMessageEvent . WaitOne ( WaitSpan ) ) ;
943+ }
885944 }
886945}
0 commit comments