统一消息系统与功能模块在校园信息管理中的应用
# 消息生产者
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='student_notifications')
channel.basic_publish(exchange='', routing_key='student_notifications', body='学生选课成功')
print(" [x] Sent '学生选课成功'")
connection.close()
# 消息消费者
def callback(ch, method, properties, body):
print(f" [x] Received {body.decode()}")
channel.basic_consume(callback, queue='student_notifications', no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!

