博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
rabbitmq
阅读量:5269 次
发布时间:2019-06-14

本文共 2597 字,大约阅读时间需要 8 分钟。

一 、安装:

参考:

执行sudo apt-get install rabbitmq-server报错:The following packages have unmet dependencies: linux-generic : Depends: linux-headers-generic (= 4.4.0.127.133) but 4.4.0.109.114 is to be installed rabbitmq-server : Depends: erlang-nox (>= 1:13.b.3) but it is not going to be installed or                            esl-erlang but it is not installable#### 执行sudo apt-get install -f sudo apt-get install erlang-noxsudo apt-get install rabbitmq-server

二、注册用户和管理:

Ubuntu上安装和使用RabbitMQ1. 安装RabbitMQ服务软件包输入以下命令进行安装#apt install rabbitmq-server 2.安装完成后在rabbitMQ中添加用户命令:#rabbitmqctl add_user username password将用户设置为管理员(只有管理员才能远程登录)命令:#rabbitmqctl set_user_tags username administrator同时为用户设置读写等权限命令:#rabbitmqctl set_permissions -p / username ".*" ".*" ".*" 3.安装RabbitMQ监控管理插件进行RabbitMQ的管理命令:#rabbitmq-plugins enable rabbitmq_management插件rabbitmq_management启动成功后就可以通过web页面进行RabbitMQ的监控和管理 4.使用rabbitmq_management插件进行监控和管理使用firefox浏览器登录:http://localhost:15672在登录页面使用 guest/guest用户名和密码登录RabbitMQ管理系统,在系统中可以对RabbitMQ服务进行channel,queue,用户等的管理 PS:Guest账号不能远程登录。如果还不能远程访问或远程登录检查是不是5672, 15672端口没有开放!!!!!!

三、简单使用:

参考:

生产者:# !/usr/bin/env pythonimport pikacredentials = pika.PlainCredentials('admin','123456')connection = pika.BlockingConnection(pika.ConnectionParameters(    '192.168.56.19',5672,'/',credentials))channel = connection.channel()# 声明queuechannel.queue_declare(queue='balance')# n RabbitMQ a message can never be sent directly to the queue, it always needs to go through an exchange.channel.basic_publish(exchange='',                      routing_key='balance',                      body='Hello World!')print(" [x] Sent 'Hello World!'")connection.close()消费者:# _*_coding:utf-8_*___author__ = 'Alex Li'import pikacredentials = pika.PlainCredentials('admin','123456')connection = pika.BlockingConnection(pika.ConnectionParameters(    '192.168.56.19',5672,'/',credentials))channel = connection.channel()# You may ask why we declare the queue again ‒ we have already declared it in our previous code.# We could avoid that if we were sure that the queue already exists. For example if send.py program# was run before. But we're not yet sure which program to run first. In such cases it's a good# practice to repeat declaring the queue in both programs.channel.queue_declare(queue='balance')def callback(ch, method, properties, body):    print(" [x] Received %r" % body)channel.basic_consume(callback,                      queue='balance',                      no_ack=True)print(' [*] Waiting for messages. To exit press CTRL+C')channel.start_consuming()

转载于:https://www.cnblogs.com/lajiao/p/9161775.html

你可能感兴趣的文章
优雅地书写回调——Promise
查看>>
android主流开源库
查看>>
AX 2009 Grid控件下多选行
查看>>
PHP的配置
查看>>
Struts框架----进度1
查看>>
Round B APAC Test 2017
查看>>
MySQL 字符编码问题详细解释
查看>>
Ubuntu下面安装eclipse for c++
查看>>
Windows 2003全面优化
查看>>
electron入门心得
查看>>
格而知之2:UIView的autoresizingMask属性探究
查看>>
我的Hook学习笔记
查看>>
js中的try/catch
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
整理推荐的CSS属性书写顺序
查看>>
ServerSocket和Socket通信
查看>>
css & input type & search icon
查看>>
源代码的下载和编译读后感
查看>>
Kafka学习笔记
查看>>
Octotree Chrome安装与使用方法
查看>>