1、安装rabbitmq
sudo apt-get install rabbitmq-server有时可能无法安装,需要修改设置
It looks like a port issue. To confirm that
systemctl stop firewalld
systemctl disable firewalld
And disable SELinux for the time being in /etc/selinux/config file
SELINUX=disabled
Try reboot your machine and see whether the issue persists.
service rabbitmq-server start 启动 status 查看状态 stop 关闭
2、增加用户以及外网访问
用户名 密码
$ sudo rabbitmqctl add_user zxl pwd
sudo rabbitmqctl set_user_tags zxl administrator
sudo rabbitmqctl set_permissions -p / zxl ".*" ".*" ".*"
3、PYTHON 代码实例
发送:
#-*- coding: UTF-8 -*-接收:
import pika
cred = pika.PlainCredentials('zxl','pwd') #账号密码
params = pika.ConnectionParameters('127.0.0.1',5672,'/',cred) #条件设置
connection = pika.BlockingConnection(params) #给定条件
channel = connection.channel()
#channel.queue_declare(queue='c_list') #创建一个c_list 队列
for i in range(0,10000):
content = 'is ' +str(i)
channel.basic_publish(exchange='',
routing_key='c_list',
body=content)
print('send hello')
print(channel)
connection.close()
#-*- coding: UTF-8 -*-
import pika
cred = pika.PlainCredentials('zxl','pwd') #账号密码
params = pika.ConnectionParameters('127.0.0.1',5672,'/',cred) #条件设置
connection = pika.BlockingConnection(params) #给定条件
channel = connection.channel()
channel.queue_declare('c_list')
def callback(ch,method,properties,body):
print " [x] Received %r" % (body,)
channel.basic_consume(callback,queue='c_list',no_ack=True)
print("starting")
channel.start_consuming()