import threading import pika # 处理消息 def callback(ch, method, properties, body): print(" [x] Received %r" % body) # channel.basic_ack(delivery_tag=method.delivery_tag) # 取出之后即删除 def consume(): credentials = pika.PlainCredentials('guest', 'guest') connection = pika.BlockingConnection(pika.ConnectionParameters( 'localhost', 5672, '/', credentials)) channel = connection.channel() # channel.exchange_declare(exchange='win-test', exchange_type='fanout') channel.queue_declare(queue='zb', durable=True) channel.basic_consume("zb", callback, auto_ack=False) print(' [*] Waiting for messages. To exit press CTRL+C') try: channel.start_consuming() except KeyboardInterrupt: pass if __name__=='__main__': thread_list = [] for i in range(5): thread_list.append(threading.Thread(target=consume)) for i in thread_list: i.start() for i in thread_list: i.join() try: while True: continue except KeyboardInterrupt: print(' [*] Exiting...')
记录——Python-RabbitMQ多线程消费队列程序
最新推荐文章于 2023-09-26 09:17:55 发布