当前位置: 首页>>代码示例>>Python>>正文


Python AMQPClient.close方法代码示例

本文整理汇总了Python中synnefo.lib.amqp.AMQPClient.close方法的典型用法代码示例。如果您正苦于以下问题:Python AMQPClient.close方法的具体用法?Python AMQPClient.close怎么用?Python AMQPClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synnefo.lib.amqp.AMQPClient的用法示例。


在下文中一共展示了AMQPClient.close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drain_queue

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
def drain_queue(queue):
    """Strip a (declared) queue from all outstanding messages"""
    if not queue:
        return

    if not queue in queues.QUEUES:
        print "Queue %s not configured" % queue
        return

    print "Queue to be drained: %s" % queue

    if not get_user_confirmation():
        return

    client = AMQPClient()
    client.connect()

    tag = client.basic_consume(queue=queue, callback=callbacks.dummy_proc)

    print "Queue draining about to start, hit Ctrl+c when done"
    time.sleep(2)
    print "Queue draining starting"

    num_processed = 0
    while True:
        client.basic_wait()
        num_processed += 1
        sys.stderr.write("Ignored %d messages\r" % num_processed)

    client.basic_cancel(tag)
    client.close()
开发者ID:vkoukis,项目名称:synnefo,代码行数:33,代码来源:dispatcher.py

示例2: main

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
def main():

    usage = "Usage: %s <instance_name>\n" % PROGNAME

    if len(sys.argv) != 2:
        sys.stderr.write(usage)
        return 1

    instance_name = sys.argv[1]

    # WARNING: This assumes that instance names
    # are of the form prefix-id, and uses prefix to
    # determine the routekey for AMPQ
    prefix = instance_name.split('-')[0]
    routekey = "ganeti.%s.event.progress" % prefix
    amqp_client = AMQPClient(confirm_buffer=10)
    amqp_client.connect()
    amqp_client.exchange_declare(settings.EXCHANGE_GANETI, "topic")

    for msg in jsonstream(sys.stdin):
        msg['event_time'] = split_time(time.time())
        msg['instance'] = instance_name

        # log to stderr
        sys.stderr.write("[MONITOR] %s\n" % json.dumps(msg))

        # then send it over AMQP
        amqp_client.basic_publish(exchange=settings.EXCHANGE_GANETI,
                                  routing_key=routekey,
                                  body=json.dumps(msg))

    amqp_client.close()
    return 0
开发者ID:AthinaB,项目名称:synnefo,代码行数:35,代码来源:progress_monitor.py

示例3: Queue

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
class Queue(object):
    """Queue.
       Required constructor parameters: hosts, exchange, client_id.
    """

    def __init__(self, **params):
        hosts = params['hosts']
        self.exchange = params['exchange']
        self.client_id = params['client_id']

        self.client = AMQPClient(hosts=hosts)
        self.client.connect()

        self.client.exchange_declare(exchange=self.exchange,
                                     type='topic')

    def send(self, message_key, user, instance, resource, value, details):
        body = Message(
            self.client_id, user, instance, resource, value, details)
        self.client.basic_publish(exchange=self.exchange,
                                  routing_key=message_key,
                                  body=json.dumps(body.__dict__))

    def close(self):
        self.client.close()
开发者ID:antonis-m,项目名称:synnefo,代码行数:27,代码来源:queue.py

示例4: purge_exchanges

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
def purge_exchanges():
    """Delete declared exchanges from RabbitMQ, after removing all queues"""
    purge_queues()

    client = AMQPClient()
    client.connect()

    exchanges = queues.EXCHANGES
    print "Exchanges to be deleted: ", exchanges

    if not get_user_confirmation():
        return

    for exch in exchanges:
        result = client.exchange_delete(exchange=exch)
        print "Deleting exchange %s. Result: %s" % (exch, result)
    client.close()
开发者ID:vkoukis,项目名称:synnefo,代码行数:19,代码来源:dispatcher.py

示例5: purge_queues

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
def purge_queues():
    """
        Delete declared queues from RabbitMQ. Use with care!
    """
    client = AMQPClient(max_retries=120)
    client.connect()

    print "Queues to be deleted: ", queues.QUEUES

    if not get_user_confirmation():
        return

    for queue in queues.QUEUES:
        result = client.queue_delete(queue=queue)
        print "Deleting queue %s. Result: %s" % (queue, result)

    client.close()
开发者ID:vkoukis,项目名称:synnefo,代码行数:19,代码来源:dispatcher.py

示例6: handle

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
    def handle(self, *args, **options):
        verbose = (options["verbosity"] == "2")
        self.keep_zombies = options["keep_zombies"]
        log_level = logging.DEBUG if verbose else logging.WARNING
        log.setLevel(log_level)

        client = AMQPClient(confirms=False)
        client.connect()

        self.client = client

        for queue in queues.QUEUES:
            dead_queue = queues.convert_queue_to_dead(queue)
            while 1:
                message = client.basic_get(dead_queue)
                if not message:
                    break
                log.debug("Received message %s", message)
                self.handle_message(message)
        client.close()
        return 0
开发者ID:AthinaB,项目名称:synnefo,代码行数:23,代码来源:queue-retry.py

示例7: main

# 需要导入模块: from synnefo.lib.amqp import AMQPClient [as 别名]
# 或者: from synnefo.lib.amqp.AMQPClient import close [as 别名]
def main():
    parser = OptionParser()
    parser.add_option('-v', '--verbose', action='store_true', default=False,
                      dest='verbose', help='Enable verbose logging')
    parser.add_option('--host', default=BROKER_HOST, dest='host',
                      help='RabbitMQ host (default: %s)' % BROKER_HOST)
    parser.add_option('--port', default=BROKER_PORT, dest='port',
                      help='RabbitMQ port (default: %s)' % BROKER_PORT, type='int')
    parser.add_option('--user', default=BROKER_USER, dest='user',
                      help='RabbitMQ user (default: %s)' % BROKER_USER)
    parser.add_option('--password', default=BROKER_PASSWORD, dest='password',
                      help='RabbitMQ password (default: %s)' % BROKER_PASSWORD)
    parser.add_option('--vhost', default=BROKER_VHOST, dest='vhost',
                      help='RabbitMQ vhost (default: %s)' % BROKER_VHOST)
    parser.add_option('--queue', default=CONSUMER_QUEUE, dest='queue',
                      help='RabbitMQ queue (default: %s)' % CONSUMER_QUEUE)
    parser.add_option('--exchange', default=CONSUMER_EXCHANGE, dest='exchange',
                      help='RabbitMQ exchange (default: %s)' % CONSUMER_EXCHANGE)
    parser.add_option('--key', default=CONSUMER_KEY, dest='key',
                      help='RabbitMQ key (default: %s)' % CONSUMER_KEY)
    parser.add_option('--callback', default=None, dest='callback',
                      help='Callback function to consume messages')
    parser.add_option('--test', action='store_true', default=False,
                      dest='test', help='Produce a dummy message for testing')
    opts, args = parser.parse_args()

    DEBUG = False
    if opts.verbose:
        DEBUG = True
    logging.basicConfig(
        format='%(asctime)s [%(levelname)s] %(name)s %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S',
        level=logging.DEBUG if DEBUG else logging.INFO)
    logger = logging.getLogger('dispatcher')

    host =  'amqp://%s:%[email protected]%s:%s' % (opts.user, opts.password, opts.host, opts.port)
    queue = opts.queue
    key = opts.key
    exchange = opts.exchange
    
    client = AMQPClient(hosts=[host])
    client.connect()

    if opts.test:
        client.exchange_declare(exchange=exchange,
                                type='topic')
        client.basic_publish(exchange=exchange,
                             routing_key=key,
                             body= json.dumps({"test": "0123456789"}))
        client.close()
        sys.exit()

    callback = None
    if opts.callback:
        cb = opts.callback.rsplit('.', 1)
        if len(cb) == 2:
            __import__(cb[0])
            cb_module = sys.modules[cb[0]]
            callback = getattr(cb_module, cb[1])

    def handle_message(client, msg):
        logger.debug('%s', msg)
        if callback:
            callback(msg)
        client.basic_ack(msg)

    client.queue_declare(queue=queue)
    client.queue_bind(queue=queue,
                      exchange=exchange,
                      routing_key=key)

    client.basic_consume(queue=queue, callback=handle_message)

    try:
        while True:
            client.basic_wait()
    except KeyboardInterrupt:
        pass
    finally:
        client.close()
开发者ID:antonis-m,项目名称:synnefo,代码行数:82,代码来源:dispatcher.py


注:本文中的synnefo.lib.amqp.AMQPClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。