def stop(self): """This method stops the channel and puts the connection back into the connection pool. Users are strongly recommended to use this method after they are done with the publishing of messages so that connection can be sent back to the pool and reused by some other user saving the cost of creating a new connection """ self._channel_closing = True self.close_channel() if not self._connection_closing: RMQConnectionPool.put_connection(self._url, self._connection) self._connection.ioloop.start()
def stop(self): """This method stops the channel and puts the connection back into the connection pool. Users are strongly recommended to use this method after they are done with the publishing of messages so that connection can be sent back to the pool and reused by some other user saving the cost of creating a new connection """ self._channel_closing = True self.close_channel() RMQConnectionPool.remove_connection(self._url) # self.close_connection() self._connection.ioloop.start()
def connect(self): """This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. Since we want the reconnection to work, we have set stop_ioloop_on_close to False, which is not the default behavior of this adapter. This method first searches the connection in the connection pool and creates a new one if not found. :rtype: pika.SelectConnection """ self._connection_closing = False self._LOGGER.info('Connecting to %s', self._url) connection = RMQConnectionPool.get_connection(self._url) if connection is None: connection = pika.SelectConnection(pika.URLParameters(self._url), self.on_connection_open, stop_ioloop_on_close=False) self._connection = connection else: self._LOGGER.info('Connection received from connection pool') self._connection = connection # Not sure about this statement but works fine if not removed!! self.add_on_connection_close_callback() self.open_channel()