標題中的所有內容:從rabbitmq的文檔中的以下方法中,我們看到發佈以交換爲參數,但消費者並不是。如何在皮卡消費者中指定交易所?
另外,雖然我在它,queue
在消費者是一樣的routing_key
在發佈?我認爲,一個路由鍵就像一個標籤,這樣用戶訂閱的標籤不同的正則表達式
代碼來使用:
import pika
def callback(ch, method, properties, body):
print " [x] Received %r" % (body,)
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_consume(callback, queue='hello', no_ack=True)
channel.start_consuming()
代碼發佈:
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
connection.close()