全部在标题中:在 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()