刪除一個存在的RabbitMQ隊列


import sys

# pip install kafka-python
sys.path.append("/usr/local/software/ELK")
from Util.RabbitMqUtil import *
queue_Name = 'kafka_queue'
host = RabbitMq_IP
creds = pika.PlainCredentials(RabbitMq_User, RabbitMq_Password)
params = pika.ConnectionParameters(host=RabbitMq_IP,
                                                                       port=int(RabbitMq_Port),
                                                                       virtual_host='/',
                                                                       heartbeat_interval=0,
                                                                       socket_timeout=5,
                                                                       credentials=pika.PlainCredentials(
                                                                           RabbitMq_User, RabbitMq_Password))


connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_delete(queue=queue_Name)
connection.close()

 創建一個隊列

import sys
# pip install kafka-python
sys.path.append("/usr/local/software/ELK")
from Util.RabbitMqUtil import *
queue_Name = 'kafka_queue'
host = RabbitMq_IP
creds = pika.PlainCredentials(RabbitMq_User, RabbitMq_Password)
params = pika.ConnectionParameters(host=RabbitMq_IP,
                                                                       port=int(RabbitMq_Port),
                                                                       virtual_host='/',
                                                                       heartbeat_interval=0,
                                                                       socket_timeout=5,
                                                                       credentials=pika.PlainCredentials(
                                                                           RabbitMq_User, RabbitMq_Password))

connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_declare(queue=queue_Name)    #聲明隊列以向其發送消息消息
#channel.basic_publish(exchange='', routing_key='test', body='Hello World!')  #注意當未定義exchange時,routing_key需和queue的值保持一致
#print('send success msg to rabbitmq')
connection.close()   #關閉連接

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM