Rabbitmq 学习(1)python版

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()



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值