示例#1
0
文件: rabbit.py 项目: isethi/yagi
    def establish_consumer_connection(self, consumer):
        # for now all consumers use the same queue connection
        # That may not be the case forever
        config = conf.config_with("rabbit_broker")
        reconnect_delay = int(config("reconnect_delay"))
        max_wait = int(config("max_wait"))

        # try a few times to connect, we might have lost the connection
        retries = 0
        while True:
            try:
                connection = BrokerConnection(
                                hostname=config("host"),
                                port=config("port"),
                                userid=config("user"),
                                password=config("password"),
                                virtual_host=config("vhost"))
                break
            except socket.error, e:
                delay = reconnect_delay * retries
                if delay > max_wait:
                    delay = max_wait
                retries += 1
                LOG.error("Could not reconnect, trying again in %d" % delay)
                time.sleep(delay)
示例#2
0
    def establish_consumer_connection(self, consumer):
        # for now all consumers use the same queue connection
        # That may not be the case forever
        config = conf.config_with("rabbit_broker")
        reconnect_delay = int(config("reconnect_delay"))
        max_wait = int(config("max_wait"))

        # This just sets the connection string. It doesn't actually
        # connect to the AMQP server yet.
        connection = BrokerConnection(
                        hostname=config("host"),
                        port=config("port"),
                        userid=config("user"),
                        password=config("password"),
                        virtual_host=config("vhost"),
                        ssl=confbool(config("ssl")))

        auto_delete = consumer.config("auto_delete") == "True" or False
        durable = consumer.config("durable") == "True" or False

        exdurable = confbool(consumer.config("exchange_durable"))
        exauto_delete = confbool(consumer.config("exchange_auto_delete"))

        # try a few times to connect, we might have lost the connection
        retries = 0
        while True:
            try:
                carrot_consumer = NotQuiteSoStupidConsumer(
                        connection=connection,
                        warn_if_exists=True,
                        exchange=consumer.config("exchange"),
                        exchange_type=consumer.config("exchange_type"),
                        routing_key=consumer.config("routing_key"),
                        queue=consumer.queue_name,
                        auto_delete=auto_delete,
                        durable=durable,
                        exchange_durable=exdurable,
                        exchange_auto_delete=exauto_delete,
                        )
                consumer.connect(connection, carrot_consumer)
                LOG.info("Connection established for %s" % consumer.queue_name)
                break
            except amqplib.client_0_8.exceptions.AMQPConnectionException, e:
                LOG.error("AMQP protocol error connecting to for queue %s" %
                           consumer.queue_name)
                LOG.exception(e)
            except socket.error, e:
                # lost connection?
                pass
示例#3
0
文件: rabbit.py 项目: xroot88/yagi
    def establish_consumer_connection(self, consumer):
        # for now all consumers use the same queue connection
        # That may not be the case forever
        config = conf.config_with("rabbit_broker")
        reconnect_delay = int(config("reconnect_delay"))
        max_wait = int(config("max_wait"))

        # This just sets the connection string. It doesn't actually
        # connect to the AMQP server yet.
        connection = BrokerConnection(hostname=config("host"),
                                      port=config("port"),
                                      userid=config("user"),
                                      password=config("password"),
                                      virtual_host=config("vhost"),
                                      ssl=confbool("ssl"))

        auto_delete = consumer.config("auto_delete") == "True" or False
        durable = consumer.config("durable") == "True" or False

        exdurable = confbool(consumer.config("exchange_durable"))
        exauto_delete = confbool(consumer.config("exchange_auto_delete"))

        # try a few times to connect, we might have lost the connection
        retries = 0
        while True:
            try:
                carrot_consumer = NotQuiteSoStupidConsumer(
                    connection=connection,
                    warn_if_exists=True,
                    exchange=consumer.config("exchange"),
                    exchange_type=consumer.config("exchange_type"),
                    routing_key=consumer.config("routing_key"),
                    queue=consumer.queue_name,
                    auto_delete=auto_delete,
                    durable=durable,
                    exchange_durable=exdurable,
                    exchange_auto_delete=exauto_delete,
                )
                consumer.connect(connection, carrot_consumer)
                LOG.info("Connection established for %s" % consumer.queue_name)
                break
            except amqplib.client_0_8.exceptions.AMQPConnectionException, e:
                LOG.error("AMQP protocol error connecting to for queue %s" %
                          consumer.queue_name)
                LOG.exception(e)
            except socket.error, e:
                # lost connection?
                pass