rabbit mq 消费消息

阅读 55

2022-02-27

 

import pika

auth = pika.PlainCredentials('admin', 'zyj@1985724')
connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.137.10',port=5672,virtual_host= '/', credentials=auth))
channel = connection.channel()

channel.queue_declare(queue='TEST01')

def callback(ch, method, properties, body):
   print(" [x] Received %r" % body)

channel.basic_consume(on_message_callback=callback,
                 queue='TEST01',
                 auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

 

精彩评论(0)

0 0 举报