统一消息平台
import pika
def callback(ch, method, properties, body):
print(f"Received {body}")
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='science_queue')
channel.basic_consume(queue='science_queue', on_message_callback=callback, auto_ack=True)
print('Waiting for messages...')
channel.start_consuming()
]]>
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='science_queue')
message = "Hello Science World!"
channel.basic_publish(exchange='', routing_key='science_queue', body=message)
print(f"Sent {message}")
connection.close()

]]>