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


Python BlockingConnection.exchange_declare方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pika import BlockingConnection [as 别名]
# 或者: from pika.BlockingConnection import exchange_declare [as 别名]
    def __init__(self, host=None, port=None, vhost=None, username=None,
                 password=None, exchange='oplog', queue=None, dump=DUMP_JSON):
        super(QueueHandler, self).__init__()

        parameters = ConnectionParameters()

        if host is not None:
            parameters.host = host
        if port is not None:
            parameters.port = port
        if vhost is not None:
            parameters.virtual_host = vhost
        if username is not None and password is not None:
            parameters.credentials = PlainCredentials(username, password)

        logger.info('Connect to queue.')
        channel = BlockingConnection(parameters).channel()

        if queue is None:
            channel.exchange_declare(exchange, 'fanout', passive=True)
        else:
            channel.exchange_delete(exchange)
            channel.exchange_declare(exchange, 'direct')
            channel.queue_declare(queue, durable=True)
            channel.queue_bind(queue, exchange)

        self.exchange = exchange
        self.channel = channel
        self.queue = queue

        if dump == DUMP_JSON:
            self.dump = lambda op: json.dumps(op, default=json_util.default)
        elif dump == DUMP_BSON:
            self.dump = lambda op: BSON.encode(op)
        else:
            raise ValueError('Invalid `dump` parameter for QueueHandler.')
开发者ID:unebutaz,项目名称:oplogstream,代码行数:38,代码来源:handlers.py


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