示例#1
0
 def connect(self):
     """
     Method connects to RabbitMQ server
     """
     log.debug("(%s) Connecting to %s", self.tag, self.amqp_url)
     conn = None
     try:
         conn = pika.SelectConnection(pika.URLParameters(self.amqp_url),
                                      self.on_connection_open,
                                      stop_ioloop_on_close=False)
     except (pika.exceptions.AMQPConnectionError, Exception), err:
         log.error("(%s) AMQP conn error: %s" % (self.tag, err))
 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.SelectConnection(
         parameters=pika.URLParameters(self._url),
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_open_error,
         on_close_callback=self.on_connection_closed)
 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
     """
     self._logger.info('Connecting to')
     return pika.SelectConnection(
         parameters=self._connection_params,
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_open_error,
         on_close_callback=self.on_connection_closed, )
示例#4
0
    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

        """
        log.debug('Connecting to %s', self._url)
        return pika.SelectConnection(pika.URLParameters(self._url),
                                     self.on_connection_open,
                                     stop_ioloop_on_close=False)
示例#5
0
 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 .....')
     return pika.SelectConnection(
         connection.getConnectionParam(),
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_open_error,
         on_close_callback=self.on_connection_closed)
    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 with %r', self._connection_params)
        return pika.SelectConnection(self._connection_params,
                                     self.on_connection_open,
                                     stop_ioloop_on_close=False)
示例#7
0
 def connect(self):
     self.connected_node = self.nodes[self.curr_node]
     console_out("Attempting to connect to " + self.nodes[self.curr_node],
                 self.get_actor())
     parameters = pika.URLParameters('amqp://*****:*****@' +
                                     self.nodes[self.curr_node] +
                                     ':5672/%2F')
     return pika.SelectConnection(
         parameters,
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_open_error,
         on_close_callback=self.on_connection_closed,
         stop_ioloop_on_close=False)
示例#8
0
    def _run(self):
        self.parent_pipe.close()

        log.debug("{} creating connection".format(self))
        self._connection = pika.SelectConnection(
            self._params,
            on_open_callback=self._on_open,
            stop_ioloop_on_close=True)

        try:
            self._connection.ioloop.start()
        except KeyboardInterrupt:
            log.debug("{} received interrupt and is exiting".format(self))
示例#9
0
    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

        """
        self._logger.debug(
            json.dumps({"msg": "Connecting to {0}".format(self._url)}))
        return pika.SelectConnection(pika.URLParameters(self._url),
                                     self.on_connection_open,
                                     stop_ioloop_on_close=False)
示例#10
0
	def __init__(self,exchange_name,queue_name,routing_key,handle_message=None):
		self.exchange_name = exchange_name
		self.queue_name = queue_name
		self.routing_key = routing_key
		self.channel = None

		#Override the handle message for consumer
		if handle_message:
			self.handle_delivery=handle_message

		super(Consumer,self).__init__()

		self.connection = pika.SelectConnection(self.connection_parameters, self.on_connected)
示例#11
0
 def connect(self):
     LOGGER.info('Connecting to %s', self._url)
     url = urlparse(self._url)
     creds = pika.PlainCredentials(url.username, url.password)
     parameters = pika.ConnectionParameters(host=url.hostname,
                                            port=url.port,
                                            virtual_host=url.path,
                                            credentials=creds)
     return pika.SelectConnection(
         parameters=parameters,
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_open_error,
         on_close_callback=self.on_connection_closed)
示例#12
0
 def __please_open_connection(self):
     params = self.__node_manager.get_connection_parameters()
     self.__start_connect_time = datetime.datetime.now()
     logdebug(LOGGER, 'Connecting to RabbitMQ at %s... (%s)', params.host,
              get_now_utc_as_formatted_string())
     loginfo(LOGGER, 'Opening connection to RabbitMQ...')
     self.thread._connection = pika.SelectConnection(
         parameters=params,
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_error,
         on_close_callback=self.on_connection_closed
         # Removed parameter, see https://github.com/pika/pika/issues/961
     )
 def start(self):
     self._load()
     parameters = self.connection_parameters
     self._connection = pika.SelectConnection(parameters, self._on_connected)
     self.logger.info('Connecting to rabbitmq: ' + RABBIT_ADDRESS)
     try:
         # Loop so we can communicate with RabbitMQ
         self._connection.ioloop.start()
     except KeyboardInterrupt:
         # Gracefully close the connection
         self._connection.close()
         # Loop until we're fully closed, will stop on its own
         self._connection.ioloop.start()
示例#14
0
    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

        """
        credentials = pika.PlainCredentials(self._rabbit_cfg['username'], self._rabbit_cfg['secret'])
        parameters = pika.ConnectionParameters(self._rabbit_cfg['host'], int(self._rabbit_cfg['port']), "/",
                                               credentials)
        return pika.SelectConnection(parameters, self.on_connection_open,
                                     stop_ioloop_on_close=False)
    def start(self):
        '''Start all of the exciting AMQPness.'''
        # Connect to RabbitMQ
        parameters = pika.URLParameters(self.url)
        connection = pika.SelectConnection(parameters, self.on_connected)

        # Main loop:
        try:
            connection.ioloop.start()
        except KeyboardInterrupt:
            # shut down gracefully
            connection.close()
            connection.ioloop.start()
示例#16
0
 def createConnection(self):
     try:
         print "Creating connection"
         self.parameters = pika.URLParameters(self._config['AMQP']['url'])
         #self._conn = pika.adapters.blocking_connection.BlockingConnection(self.parameters)
         self._conn = pika.SelectConnection(self.parameters,
                                  self.on_connection_open,
                                  stop_ioloop_on_close=False)
         return self._conn
         
     except pika.exceptions.ConnectionClosed:
         print "Connection was closed while setting up connection... exiting"
         sys.exit(1)
示例#17
0
    def connect(self):
        logger.info(f"Chasing the 🐇: {self._uri} | {self._queue_name}")

        params = pika.ConnectionParameters(self._uri,
                                           heartbeat=self._heartbeat)

        # TODO: Add on_connection_close_callback
        self._connection = pika.SelectConnection(
            parameters=params,
            on_open_callback=self.on_connection_open,
            on_open_error_callback=self.on_connection_open_error,
            on_close_callback=self.on_connection_closed,
        )
示例#18
0
    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.debug('Connecting to {}'.format(self._broker))
        return pika.SelectConnection(pika.ConnectionParameters(
            host=self._broker, credentials=self.__get_credentials()),
                                     self.on_connection_open,
                                     stop_ioloop_on_close=False)
示例#19
0
    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.SelectConnection(
            pika.ConnectionParameters(host='localhost'),
            self.on_connection_open,
            stop_ioloop_on_close=False)
示例#20
0
    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

        """
        return pika.SelectConnection(pika.URLParameters(self._url),
                                     self.on_connection_open,
                                     stop_ioloop_on_close=False)
示例#21
0
	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

		"""
		self._url = "amqp://{}:{}@{}/{}".format(self.username, self.password, self.base_url, self.vhost)
		log.debug('Connecting to %s', self.base_url)
		return pika.SelectConnection(pika.URLParameters(self._url),
									 self.on_connection_open,
									 stop_ioloop_on_close=False)
示例#22
0
 def __please_open_connection(self):
     params = self.__node_manager.get_connection_parameters()
     self.__start_connect_time = datetime.datetime.now()
     logdebug(LOGGER, 'Connecting to RabbitMQ at %s... (%s)', params.host,
              get_now_utc_as_formatted_string())
     loginfo(LOGGER, 'Opening connection to RabbitMQ...')
     self.thread._connection = pika.SelectConnection(
         parameters=params,
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_error,
         on_close_callback=self.on_connection_closed,
         stop_ioloop_on_close=False  # why? see below. 
     )
示例#23
0
    def start(self):
        if len(self._subscriptions) == 0:
            pass
        params = pika.URLParameters(self.broker_url)

        self.connection = pika.SelectConnection(params, self._on_connected)
        self._logger.debug('Connection created')
        self.connection.add_on_close_callback(self._on_connection_closed)
        try:
            self._logger.debug('IO Loop starting')
            self.connection.ioloop.start()
        except KeyboardInterrupt:
            self._logger.info("KeyboardInterrupt. Adios!")
示例#24
0
    def connect(self):
        """Connect to RabbitMQ, returning the connection handle.

        When the connection is established, the on_connection_open method
        will be invoked by pika.

        :rtype: pika.SelectConnection

        """
        self._LOGGER.info('Connecting to %s with queue %s and exchange %s', self._url, self.queue, self.exchange)
        return pika.SelectConnection(pika.URLParameters(self._url),
                                     self.on_connection_open,
                                     self.on_connection_error,
                                     stop_ioloop_on_close=False)
示例#25
0
    def check_message_queue(self):
        class Helper:
            """
            Helper class to close a connection and memorize a return value
            """
            def __init__(self):
                self.ret = True

            def close_connection(self, conn, ret):
                self.ret = ret
                conn.close()
                if ret is False:
                    logger.error(
                        "ERROR in RabbitMQ connection: Connection timed out")

        helper = Helper()
        """
        Try to connect to RabbitMQ server with pika

        If the connection will timeout or an exception will be thrown, 
        then the connection failed

        NOTES: workaround needed - the built-in connection timeout parameters 
        of pika don't work, so we had to use the callbacks of SelectConnection
        """
        try:
            # Connect to RabbitMQ server
            parameters = pika.URLParameters(settings.BROKER_URL)

            # Connection ok
            # Using on_connect callback of SelectConnection to close the
            # connection(and the ioloop implicitly) and set the return
            # value to True
            connection = pika.SelectConnection(
                parameters, lambda conn: helper.close_connection(conn, True))

            # Connection timeout
            # Using on_timeout callback of SelectConnection to close
            # connection and set the return value to False
            connection.ioloop.add_timeout(
                settings.RABBITMQ_CHECK_TIMEOUT,
                lambda: helper.close_connection(connection, False))

            # Start the ioloop
            connection.ioloop.start()

        # Connection error
        except pika.exceptions.AMQPConnectionError, e:
            logger.error("ERROR in RabbitMQ connection")
            return False
示例#26
0
 def connect(self):
     LOGGER.info('Connecting to %s:%s' % (self.host, self.port))
     credentials = pika.PlainCredentials(self.username, self.password)
     parameters = pika.ConnectionParameters(self.host,
                                            self.port,
                                            self.vhost,
                                            credentials,
                                            ssl=self.ssl,
                                            connection_attempts=3,
                                            retry_delay=2,
                                            socket_timeout=5)
     return pika.SelectConnection(parameters,
                                  self.on_connection_open,
                                  stop_ioloop_on_close=False)
示例#27
0
    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.host)
        self.credentials = pika.PlainCredentials(self.user, self.password)
        return pika.SelectConnection(pika.ConnectionParameters(host=self.host, credentials=self.credentials,
                                                               heartbeat_interval=60),
                                     self.on_connection_open, self.add_on_open_error_callback,
                                     stop_ioloop_on_close=False)
示例#28
0
 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:%d', self._parameter.host,
                 self._parameter.port)
     return pika.SelectConnection(
         self._parameter,
         on_open_callback=self.on_connection_open,
         on_open_error_callback=self.on_connection_open_error,
         on_close_callback=self.on_connection_closed,
         stop_ioloop_on_close=False)
示例#29
0
 def connect(self):
     """Connect to the RabbitMQ server and return the connection handle.
     When the connection is established, on_connection_open will be called.
     """
     if self.loggername is not None:
         #logging.getLogger(self.loggername).debug('Connecting to %s', self.url)
         self.logger.debug('Connecting to [{:s}:{:d}]'.format(self.cfg['ip'], self.cfg['port']))
     #return pika.SelectConnection(pika.URLParameters(self.url),
     #                             self.on_connection_open,
     #                             stop_ioloop_on_close=False)
     return pika.SelectConnection(parameters=self.parameters,
                                  on_open_callback=self.on_connection_open,
                                  on_open_error_callback=self.on_connection_error,
                                  stop_ioloop_on_close=True)
示例#30
0
    def connect(self):
        """这个方法连接到RabbitMQ,返回连接句柄。
            连接建立后,pika会调用on_connection_open方法。
            如果要重新连接,请确保将stop_ioloop_on_close设置为False,这不是此适配器的默认行为。

        :rtype: pika.SelectConnection

        """
        LOGGER.info('连接到 %s', self._url)
        return pika.SelectConnection(
            pika.URLParameters(self._url),
            on_open_callback=self.on_connection_open,
            on_close_callback=self.on_connection_closed,
            stop_ioloop_on_close=False)