统一消息系统与代理商的技术整合
import pika
# 连接到RabbitMQ服务器
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
# 创建队列
channel.queue_declare(queue='agent_queue')
# 发送消息
message = 'Hello Agent!'
channel.basic_publish(exchange='',
routing_key='agent_queue',
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('localhost'))
channel = connection.channel()

channel.queue_declare(queue='agent_queue')
channel.basic_consume(queue='agent_queue',
on_message_callback=callback,
auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!

