我使用pika库使用rabbitmctl.我使用以下代码创建一个Producer
#!/usr/bin/env python
import pika
import time
import json
import datetime
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
#print " current time: %s " % (str(int((time.time())*1000)))
print body
channel.basic_consume(callback,
queue='hello',
no_ack=True)
channel.start_consuming()
Run Code Online (Sandbox Code Playgroud)
由于我每次创建一个现有队列(如果没有创建队列,则覆盖队列的创建)队列因此而被破坏.现在我想删除队列.我这样做吗?
Ped*_*eck 21
由于这似乎是一个维护过程,而不是您将在代码上定期执行的操作,因此您可能应该使用RabbitMQ管理插件并从那里删除队列.
无论如何,你可以用pika删除它:
channel.queue_delete(queue='hello')
Run Code Online (Sandbox Code Playgroud)
https://pika.readthedocs.org/en/latest/modules/channel.html#pika.channel.Channel.queue_delete
详细的答案如下(参考以上非常有用和有用的答案)
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.queue_delete(queue='hello')
connection.close()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8926 次 |
最近记录: |