下载地址
## erlang 下载地址
https://packagecloud.io/rabbitmq/erlang?page=6## rabbitmq 下载地址
https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.8.29-1.el7.noarch.rpm?distro_version_id=140
Rabbitmq的RPM包安装
## 下载
wget --content-disposition "https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-21.3.8.18-1.el7.x86_64.rpm/download.rpm?distro_version_id=140"##
wget --content-disposition "https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.8.29-1.el7.noarch.rpm/download.rpm?distro_version_id=140"###
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
默认账号密码:guest/guest,rabbitmq 从 3.3.0 开始禁止使用 guest/guest 权限通过除 localhost 外的访问。
创建后创建用户相关命令
## 创建用户,第二个knight 为密码
rabbitmqctl add_user knight knight##设置用户分配操作权限
rabbitmqctl set_user_tags knight administrator##
rabbitmqctl set_permissions -p / knight ".*" ".*" ".*"##
systemctl status rabbitmq-server## 开启 web 访问
rabbitmq-plugins enable rabbitmq_management
其他常用命令
##
https://blog.csdn.net/knight_zhou/article/details/132599796
Python读写
### 依赖库
pip install pika
参考文章
##
https://support.huaweicloud.com/intl/zh-cn/devg-rabbitmq/rabbitmq-devg-003.html
生产者
import pika
import randomrandom_int = random.randint(1,100)
#Connection information
conf = {'host': 'yy.cn','port': 5672,'queue_name': 'queue-test','username': 'admin','password': 'admin'
}credentials = pika.PlainCredentials(conf['username'], conf['password'])
parameters = pika.ConnectionParameters(conf['host'],conf['port'],'/',credentials)connection = pika.BlockingConnection(parameters)
channel = connection.channel()channel.queue_declare(conf['queue_name'])# data = bytes(str(random_int), encoding="utf-8")
data = bytes("cc", encoding="utf-8")channel.basic_publish(exchange='',routing_key=conf['queue_name'],body=data)print("produce...")connection.close()
消费者
import pika#Connection information
conf = {'host': 'yy.cn','port': 5672,'queue_name': 'queue-test','username': 'admin','password': 'admin'
}credentials = pika.PlainCredentials(conf['username'], conf['password'])
parameters = pika.ConnectionParameters(conf['host'],conf['port'],'/',credentials)connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(conf['queue_name'])def callback(ch, method, properties, body):print(" [x] Received %r" % body.decode('utf-8'))channel.basic_consume(queue=conf['queue_name'], on_message_callback=callback, auto_ack=True)print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()