1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| import pika
credentials = pika.PlainCredentials("guest", "guest") connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', credentials=credentials)) channel = connection.channel()
channel.queue_declare(queue='test', arguments={"x-max-priority": 10})
channel.basic_publish( properties=pika.BasicProperties(priority=5), exchange='', routing_key='test', body='test'.encode('utf-8') )
connection.close()
|
channel.queue_declare(queue='test', arguments={"x-max-priority": 10})
在声明队列的时候声明最大优先级.
在发布消息的时候通过properties=pika.BasicProperties(priority=5)
针对不同的消息来设置不同的优先级.
消费的时候,不同优先级,优先级高的先被消费,相同优先级的,会按照FIFO
的顺序.