26 lines
801 B
Python
26 lines
801 B
Python
import pika
|
|
from config import *
|
|
|
|
|
|
|
|
def send_message(message):
|
|
# 连接 RabbitMQ
|
|
credentials = pika.PlainCredentials(mq_user, mq_password)
|
|
connection = pika.BlockingConnection(
|
|
pika.ConnectionParameters(host='localhost', credentials=credentials)
|
|
)
|
|
channel = connection.channel()
|
|
|
|
channel.exchange_declare(exchange='zzck_exchange', exchange_type='fanout')
|
|
# 声明队列
|
|
# channel.queue_declare(queue=mq_queue)
|
|
|
|
# 发送消息
|
|
channel.basic_publish( exchange='zzck_exchange',
|
|
routing_key='',
|
|
body=message,
|
|
properties=pika.BasicProperties(
|
|
expiration='10' # 消息1秒后过期
|
|
)
|
|
)
|
|
connection.close() |