新RabbitMQ精讲 提高工程实践能力 培养架构思惟

新RabbitMQ精讲 提高工程实践能力 培养架构思惟

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()
相关文章
相关标签/搜索