Linux启动RabbitMQ涉及的基础概念包括RabbitMQ本身,这是一个开源的消息代理和队列服务器,用于通过轻量级和可靠的消息在服务器之间进行通信。RabbitMQ运行在AMQP(高级消息队列协议)上,支持多种消息协议,如MQTT、STOMP等。
http://your_server_ip:15672
,默认用户名和密码都是guest
。/etc/rabbitmq/rabbitmq.conf
是否有误。# 发送消息
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
print(" [x] Sent 'Hello World!'")
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='hello')
channel.basic_consume(queue='hello',
auto_ack=True,
on_message_callback=callback)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
通过以上步骤和代码示例,可以在Linux系统上成功启动RabbitMQ并进行基本的消息发送和接收操作。
领取专属 10元无门槛券
手把手带您无忧上云