浅见池也 发表于 2018-8-7 07:37:18

python rabbitmq 队列持久化

import pika  

  
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
  
channel = connection.channel()
  

  

  
channel.queue_declare(queue='hello',durable=True)##队列持久化,队列重启后也存在,不保证数据是否存在
  
# channel.queue_delete(queue="task_queue")
  
# for i in range(100):
  
channel.basic_publish(exchange='',
  
                      routing_key='hello',
  
                      body="hello world",
  
                      properties=pika.BasicProperties(delivery_mode=2) ##数据持久化
  
                      )
  
# print("Sent 'hello world!'")
  
connection.close()
页: [1]
查看完整版本: python rabbitmq 队列持久化