我是Rabbitmq的消费者,它从特定队列中读取并执行某些操作。 现在我想批量执行该操作。我无法弄清楚消费者只是将整个上下文保存在列表中的方式,即(ch,方法,道具,正文),然后当大小大于' n'时,所需的最小批量大小,我可以执行批处理操作,并执行以下操作:
if len(no_of_messages) > 10:
responses = batch_operation(messages)
for response in responses:
ch, method, props, body = response
ch.basic_publish(exchange='',
routing_key=props.reply_to,
properties=pika.BasicProperties(
correlation_id=props.correlation_id),
body=str(body))
关于如何去做的任何想法?我这样开始消费者:
channel.basic_qos(prefetch_count=1)
channel.basic_consume(some_function_that_does_above_stuffs, queue='rpc_queue')
print(" [x] Awaiting RPC requests")
channel.start_consuming()