V:ititit111222333
import pika
import time
from datetime import datetime
def callback(ch, method, porperties, body):
print (‘*‘*16)
print (str(datetime.now())[:-3], ‘new message on‘, method.exchange)
print (str(datetime.now())[:-3], ‘routing key is: ‘, method.routing_key)
print (str(datetime.now())[:-3], ‘type is: ‘, porperties.type)
print (str(datetime.now())[:-3], ‘properties is: ‘, porperties)
print (str(datetime.now())[:-3], ‘body is: ‘)
print (str(datetime.now())[:-3], body)
print (‘‘)
cred = pika.PlainCredentials(‘username‘,‘password‘)
con = pika.BlockingConnection(pika.ConnectionParameters(host =‘Ipaddress‘, credentials = cred))
chann = con.channel()
que = chann.queue_declare(queue="test",durable = False, exclusive = False)
key = ‘#‘
ex = ‘IGT.Exchange.Master‘
chann.queue_bind(exchange = ex, queue = que.method.queue, routing_key = key)
chann.basic_consume("test", callback, auto_ack=True)
print (‘ready to listen to ‘ + ex)
chann.start_consuming()
原文:https://blog.51cto.com/15063244/2655451