本文整理汇总了Python中pika.adapters.BlockingConnection.process_data_events方法的典型用法代码示例。如果您正苦于以下问题:Python BlockingConnection.process_data_events方法的具体用法?Python BlockingConnection.process_data_events怎么用?Python BlockingConnection.process_data_events使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pika.adapters.BlockingConnection
的用法示例。
在下文中一共展示了BlockingConnection.process_data_events方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blocking_submitter
# 需要导入模块: from pika.adapters import BlockingConnection [as 别名]
# 或者: from pika.adapters.BlockingConnection import process_data_events [as 别名]
def blocking_submitter(parameters, data_queue,
properties=DEFAULT_PROPERTIES):
while True:
try:
connection = BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='sandbox', durable=True)
except Exception:
log.error('connection failure', exc_info=True)
time.sleep(1)
continue
while True:
log.info('waiting on data queue')
try:
data = data_queue.get(timeout=1)
except Queue.Empty:
try:
connection.process_data_events()
except AMQPConnectionError:
break
continue
log.info('got data to submit')
try:
channel.basic_publish(exchange='',
routing_key='sandbox',
body=data,
properties=properties,
mandatory=True)
except Exception:
log.error('submission failed', exc_info=True)
data_queue.put(data)
break
log.info('submitted data to broker')