首先安装pika
pip insatll pika
?
?其中EX1,KEY1,EX2,KEY2, 分别代表MQ management 界面图中 1 2 3 4位置的参数
?
import pika
import json
import datetime
args= {'x-dead-letter-exchange':'EX1','x-dead-letter-routing-key':'KEY1'}
message = json.dumps(.....)
connection = pika.BlockingConnection(pika.ConnectionParameters(host='....', port=5672,credentials=pika.PlainCredentials('...', '...')))
channel = connection.channel()
channel.queue_declare(queue='....',durable=True,arguments=args)
channel.basic_publish(exchange='EX2', routing_key='KEY2', body=message)
connection.close()
|