新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()
相關文章
相關標籤/搜索