def __init__(self, host='localhost', port=5672, username='******', password='******'): """ Creates a new instance of ``RabbitMQClient`` with specified connection parameters and user credentials. :param str host: RabbitMQ server host name or IP address. :param int port: RabbitMQ server port. :param str username: RabbitMQ username. :param str password: RabbitMQ password. """ self._host = host self._port = port self._username = username self._password = password self._connection = pika.TornadoConnection( pika.ConnectionParameters( host=self._host, port=self._port, credentials=pika.PlainCredentials( username=self._username, password=self._password, ), ), on_open_callback=self._on_connection_open, on_open_error_callback=self._on_connection_open_error, ) self._channel = None self._client_queue = None self._server_queue = None self._pending_requests = dict()
def connect(self, ioloop): """ This method connects to RabbitMQ, returning the state. When the connection is established, the on_connection_open method will be invoked by pika. This method waits for the connection to be open :param ioloop: the ioloop to be used by the tornadoConnection :return: True if the connection is successful """ self.logger.info( "pid:{} AMQP connecting to: exchange:{} host:{} port: {}".format( os.getpid(), self._config.exchange, self._config.host, self._config.port)) credentials = pika.PlainCredentials(self._config.user, self._config.password) pika.TornadoConnection( pika.ConnectionParameters(host=self._config.host, port=self._config.port, credentials=credentials), self._on_connection_open, on_open_error_callback=self._on_connection_open_error, on_close_callback=self._on_connection_closed, custom_ioloop=ioloop) res = yield self._isStarted return res
def _connect(self) -> pika.TornadoConnection: """ This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. """ logger.info('Set Up connection to: {}'.format(self._url)) return pika.TornadoConnection(pika.URLParameters(self._url), self._on_connection_open)
def connect(self): try: credentials = pika.PlainCredentials(config.RMQ_USER, config.RMQ_PASSWORD) param = pika.ConnectionParameters(host=config.RMQ_HOST, credentials=credentials) self._connection = pika.TornadoConnection( param, on_open_callback=self.on_connected) except Exception as e: print('Something went wrong... %s', e)
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. :rtype: pika.SelectConnection """ LOGGER.info('Connecting to %s', self._url) return pika.TornadoConnection(pika.URLParameters(self._url), self.on_connection_open, on_open_error_callback=self.on_open_error)
def connect(self): """Create the low-level AMQP connection to RabbitMQ. :rtype: pika.TornadoConnection """ self.set_state(self.STATE_CONNECTING) self.handle = pika.TornadoConnection( self._connection_parameters, on_open_callback=self.on_open, on_open_error_callback=self.on_open_error, stop_ioloop_on_close=False, custom_ioloop=self.io_loop)
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. :rtype: pika.SelectConnection """ LOGGER.info('Connecting to %s', self._url) #TODO: get this from constructor return pika.TornadoConnection(pika.ConnectionParameters('127.0.0.1'), self.on_connection_open, stop_ioloop_on_close=self._is_sink)
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. :rtype: pika.TornadoConnection """ LOGGER.debug('Connecting to %s', self._url) return pika.TornadoConnection( parameters=self._parameters, on_open_callback=self._on_connection_open, on_open_error_callback=self._on_connection_open_error, on_close_callback=self._on_connection_closed, custom_ioloop=self._ioloop)
def connect_to_rabbitmq(self, config, name): """Connect to RabbitMQ returning the connection handle. :param dict config: The Connections section of the configuration :param str name: The name of the connection """ self.set_state(self.STATE_CONNECTING) self.connection_id += 1 params = self.get_connection_parameters(config[name]) LOGGER.debug('Connecting to %s:%i:%s as %s', params.host, params.port, params.virtual_host, params.credentials.username) return pika.TornadoConnection(params, self.on_connect_open, self.on_connect_failed, self.on_closed, False, self.ioloop)
def connect(self): if self.connecting: MQ_LOG.info('mq already connecting to RabbitMQ') return MQ_LOG.info('connecting to RabbitMQ ... host:%s', MQ_HOST) self.connecting = True credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASSWD) param = pika.ConnectionParameters(host=MQ_HOST, credentials=credentials) self.connection = pika.TornadoConnection( param, on_open_callback=self.on_conn_open, on_close_callback=self.on_conn_close, on_open_error_callback=self.on_conn_error)
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. :rtype: pika.TornadoConnection """ if not self.idle and not self.closed: raise ConnectionStateError(self.state_description) LOGGER.debug('Connecting to %s', self.url) self.state = self.STATE_CONNECTING self.connection = pika.TornadoConnection( parameters=self.parameters, on_open_callback=self.on_connection_open, on_open_error_callback=self.on_connection_open_error, on_close_callback=self.on_connection_closed, custom_ioloop=self.io_loop)
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. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter. :rtype: pika.SelectConnection """ LOGGER.info('Connecting to %s', self._url) # return pika.SelectConnection(pika.URLParameters(self._url), # self.on_connection_open, # stop_ioloop_on_close=False) return pika.TornadoConnection(parameters=pika.URLParameters(self._url), on_open_callback=self.on_connection_open, on_open_error_callback=None, on_close_callback=None, stop_ioloop_on_close=False, custom_ioloop=None)
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. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter. """ if self._state is ConnectorState.CONNECTED: return self._connecting_future LOGGER.info('Connecting to %s', self.get_connection_params()) if self._state is ConnectorState.DISCONNECTED: self._state = ConnectorState.CONNECTING self._connection = pika.TornadoConnection( self._connection_params, on_open_callback=self._on_connection_open, on_close_callback=self._on_connection_closed, custom_ioloop=self._loop) return self._connecting_future
def connect(self): """ Connect to AMQP server. This method should be called after :func:`topika.connection.Connection.__init__` .. note:: This method is called by :func:`connect`. You shouldn't call it explicitly. :rtype: :class:`pika.TornadoConnection` """ if self.__closing and self.__closing.done(): raise RuntimeError("Invalid connection state") with (yield self.__write_lock.acquire()): self._connection = None LOGGER.debug("Creating a new AMQP connection: %s", self) connect_future = tools.create_future(loop=self.loop) connection = pika.TornadoConnection( parameters=self.__connection_parameters, custom_ioloop=self.loop, on_open_callback=connect_future.set_result, on_close_callback=partial(self._on_connection_lost, connect_future), on_open_error_callback=partial(self._on_connection_refused, connect_future), ) connection.channel_cleanup_callback = self._channel_cleanup connection.channel_cancel_callback = self._on_channel_cancel result = yield connect_future LOGGER.debug("Connection ready: %r", self) self._connection = connection raise gen.Return(result)
def connect(self): return pika.TornadoConnection( self.parameters, self.on_connection_open, on_close_callback=self.on_connection_close)
def connect(self): print('Connecting..') return pika.TornadoConnection(pika.ConnectionParameters('localhost'), self.on_connection_open, stop_ioloop_on_close=False)
def connect(self): logger.info('Connecting to RabbitMQ') return pika.TornadoConnection( pika.ConnectionParameters(host='192.168.2.194'), self.on_connection_open, stop_ioloop_on_close=False)