本文整理汇总了Python中pika.BlockingConnection.queue_declare方法的典型用法代码示例。如果您正苦于以下问题:Python BlockingConnection.queue_declare方法的具体用法?Python BlockingConnection.queue_declare怎么用?Python BlockingConnection.queue_declare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pika.BlockingConnection
的用法示例。
在下文中一共展示了BlockingConnection.queue_declare方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pika import BlockingConnection [as 别名]
# 或者: from pika.BlockingConnection import queue_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.')