我们提供消息推送系统招投标所需全套资料,包括消息推送系统介绍PPT、消息推送系统产品解决方案、
消息推送系统产品技术参数,以及对应的标书参考文件,详请联系客服。
import pika
def send_message(message):
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='agent_queue')
channel.basic_publish(exchange='', routing_key='agent_queue', body=message)
print(f" [x] Sent {message}")
connection.close()

import pika
def callback(ch, method, properties, body):
print(f" [x] Received {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()

from flask import Flask, request, jsonify
app = Flask(__name__)
subscriptions = {}
@app.route('/subscribe', methods=['POST'])
def subscribe():
data = request.json
agent_id = data['agent_id']
topic = data['topic']
if agent_id not in subscriptions:
subscriptions[agent_id] = []
subscriptions[agent_id].append(topic)
return jsonify({"status": "success", "message": f"Agent {agent_id} subscribed to {topic}"}), 200
if __name__ == '__main__':
app.run(debug=True)