@@ -58,7 +58,7 @@ def __init__(
5858 self ._addr : Optional [str ] = uri
5959 self ._addrs : Optional [list [str ]] = uris
6060 self ._conn : BlockingConnection
61- self ._management : Management
61+ self ._managements : list [ Management ] = []
6262 self ._reconnect = reconnect
6363 self ._conf_ssl_context : Optional [SslConfigurationContext ] = ssl_context
6464 self ._ssl_domain = None
@@ -108,21 +108,20 @@ def dial(self) -> None:
108108 on_disconnection_handler = self ._on_disconnection ,
109109 )
110110
111- self ._open ()
111+ # self._open()
112112 logger .debug ("Connection to the server established" )
113113
114- def _open (self ) -> None :
115- self ._management = Management (self ._conn )
116- self ._management .open ()
117-
118114 def management (self ) -> Management :
119115 """
120116 Get the management interface for this connection.
121117
122118 Returns:
123119 Management: The management interface for performing administrative tasks
124120 """
125- return self ._management
121+ management = Management (self ._conn )
122+ management .open ()
123+ self ._managements .append (management )
124+ return management
126125
127126 # closes the connection to the AMQP 1.0 server.
128127 def close (self ) -> None :
@@ -137,6 +136,8 @@ def close(self) -> None:
137136 publisher .close ()
138137 for consumer in self ._consumers :
139138 consumer .close ()
139+ for management in self ._managements :
140+ management .close ()
140141 self ._conn .close ()
141142 except Exception as e :
142143 logger .error (f"Error closing connection: { e } " )
@@ -166,7 +167,7 @@ def publisher(self, destination: str = "") -> Publisher:
166167 )
167168 publisher = Publisher (self ._conn , destination )
168169 self ._publishers .append (publisher )
169- return self . _publishers [ self . _publishers . index ( publisher )]
170+ return publisher
170171
171172 def consumer (
172173 self ,
@@ -202,26 +203,26 @@ def consumer(
202203
203204 def _on_disconnection (self ) -> None :
204205
205- print ("disconnected" )
206-
207206 if self in self ._connections :
208207 self ._connections .remove (self )
209208
210- print ("reconnecting" )
211209 self ._conn = BlockingConnection (
212210 url = self ._addr ,
213211 urls = self ._addrs ,
214212 ssl_domain = self ._ssl_domain ,
215213 on_disconnection_handler = self ._on_disconnection ,
216214 )
217- self . _open ()
215+
218216 self ._connections .append (self )
219217
220- for index , publisher in enumerate (self ._publishers ):
221- # publisher = self._publishers.pop(index)
222- # address = publisher.address
223- self ._publishers .remove (publisher )
224- # self._publishers.insert(index, Publisher(self._conn, address))
218+ for i , management in enumerate (self ._managements ):
219+ # Update the broken connection and sender in the management
220+ self ._managements [i ].update_connection (self ._conn )
221+
222+ for i , publisher in enumerate (self ._publishers ):
223+ # Update the broken connection and sender in the publisher
224+ self ._publishers [i ].update_connection (self ._conn )
225225
226226 for i , consumer in enumerate (self ._consumers ):
227- self ._consumers .remove (consumer )
227+ # Update the broken connection and sender in the consumer
228+ self ._consumers [i ].update_connection (self ._conn )
0 commit comments