构建基于统一消息的大学融合门户与师范大学信息系统
// 安装 RabbitMQ
sudo apt-get install rabbitmq-server
// 启动服务
sudo systemctl start rabbitmq-server
]]>
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='course_updates')
message = "New course added: Math 101"
channel.basic_publish(exchange='', routing_key='course_updates', body=message)
print(" [x] Sent %r" % message)
connection.close()
]]>
import pika
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='course_updates')
channel.basic_consume(queue='course_updates', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!