RabbitMQ安装和配置
RabbitMQ:
MQ:message queue.MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们。消 息传递指的是程序之间通过在消息中发送数据进行通信,而不是通过直接调用彼此来通信,直接调用通常是用于诸如远程过程调用的技术。排队指的是应用程序通过 队列来通信。队列的使用除去了接收和发送应用程序同时执行的要求。其中较为成熟的MQ产品有IBM WEBSPHERE MQ。ActiveMQ.
下载:http://www.rabbitmq.com/download.html
首先要安装Erlange:http://www.erlang.org/download.html
配置环境变量 ERLANG_HOME C:\Program Files (x86)\erl6.1
添加到PATH %ERLANG_HOME%\bin;
配置环境变量 C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-2.8.0
添加到PATH %RABBITMQ_SERVER%\sbin;
进入sbin目录,启动,或者在star menu点击start。
rabbitmq-service.bat start
接着安装管理工具
参考官方文档:http://www.rabbitmq.com/management.html
操作起来很简单,只需要在DOS下面,进入安装目录(C:\RabbitMQ Server\rabbitmq_server-3.2.2\sbin)执行如下命令就可以成功安装。
rabbitmq-plugins enable rabbitmq_management
可以通过访问http://localhost:15672进行测试,默认的登陆账号为:guest,密码为:guest。
rabbitmq-service stop
rabbitmq-service install
rabbitmq-service start
如果访问成功了,恭喜,整个rabbitMQ安装完成了。
RabbitMQ服务端是用AMPQ协议的, 而客户端支持多种语言(Java, .NET, C/C++,Erlang......)。下面我们准备用java来写一个hello world,测试RabbitMQ是否安装OK。
Install the Server
Firstly, download and run the Erlang Windows Binary File. It takes around 5 minutes.
Then just run the installer, rabbitmq-server-3.3.5.exe. It takes around 2 minutes, and will set RabbitMQ up and running as a service, with a default configuration.
Run RabbitMQ Service
- Customise RabbitMQ Environment Variables
-
The service will run fine using its default settings. You may want to customise the RabbitMQ environment or edit configuration.
- Run RabbitMQ
-
The RabbitMQ service starts automatically. You can stop/reinstall/start the RabbitMQ service from the Start Menu.
- Manage the Service
-
You can find links to RabbitMQ directories in the Start Menu.
There is also a link to a command prompt window that will start in the sbin dir, in the Start Menu. This is the most convenient way to run the various command line tools.
Default user access
The broker creates a user guest with password guest. Unconfigured clients will in general use these credentials. By default, these credentials can only be used when connecting to the broker as localhost so you will need to take action before connecting fromn any other machine.
See the documentation on access control for information on how to create more users, delete the guestuser, or allow remote access to the guest user.
Managing the Broker
To stop the broker or check its status, use rabbitmqctl.bat in sbin (as an administrator).
- Stopping the Broker
-
Use rabbitmqctl stop.
- Checking the Broker Status
-
Use rabbitmqctl status. All rabbitmqctl commands will report the node absence if no broker is running (i.e. nodedown).
More info on rabbitmqctl
Logging
Output from the server is sent to a RABBITMQ_NODENAME.log file in the RABBITMQ_LOG_BASE directory. Additional log data is written to RABBITMQ_NODENAME-sasl.log.
The broker always appends to the log files, so a complete log history is retained.
You can rotate logs using rabbitmqctl rotate_logs.
Troubleshooting When Running as a Service
In the event that the Erlang VM crashes whilst RabbitMQ is running as a service, rather than writing the crash dump to the current directory (which doesn't make sense for a service) it is written to anerl_crash.dump file in the base directory of the RabbitMQ server (set by the RABBITMQ_BASE environment variable, defaulting to %APPDATA%\%RABBITMQ_SERVICENAME% - typically %APPDATA%\RabbitMQ otherwise).
使用场景:
在项目中,将一些无需即时返回且耗时的操作提取出来,进行了异步处理,而这种异步处理的方式大大的节省了服务器的请求响应时间,从而提高了系统的吞吐量
编程测试rabbitMQ:
http://www.rabbitmq.com/tutorials/tutorial-one-java.html
下面代码来自上面网址:
Send:
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel; public class Send { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'"); channel.close();
connection.close();
}
}
The connection abstracts the socket connection, and takes care of protocol version negotiation and authentication and so on for us. Here we connect to a broker on the local machine - hence the localhost. If we wanted to connect to a broker on a different machine we'd simply specify its name or IP address here.
Next we create a channel, which is where most of the API for getting things done resides.
To send, we must declare a queue for us to send to; then we can publish a message to the queue。
Declaring a queue is idempotent - it will only be created if it doesn't exist already. The message content is a byte array, so you can encode whatever you like there.
The code (in Recv.java) has almost the same imports as Send:
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
The extra QueueingConsumer is a class we'll use to buffer the messages pushed to us by the server.
Setting up is the same as the sender; we open a connection and a channel, and declare the queue from which we're going to consume. Note this matches up with the queue that sendpublishes to.
public class Recv { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv)
throws java.io.IOException,
java.lang.InterruptedException { ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
...
}
}
Note that we declare the queue here, as well. Because we might start the receiver before the sender, we want to make sure the queue exists before we try to consume messages from it.
We're about to tell the server to deliver us the messages from the queue. Since it will push us messages asynchronously, we provide a callback in the form of an object that will buffer the messages until we're ready to use them. That is what QueueingConsumer does.
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer); while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
QueueingConsumer.nextDelivery() blocks until another message has been delivered from the server.
几个概念:

Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列。
Queue:消息队列载体,每个消息都会被投入到一个或多个队列。
Binding:绑定,它的作用就是把exchange和queue按照路由规则绑定起来。
Routing Key:路由关键字,exchange根据这个关键字进行消息投递。
vhost:虚拟主机,一个broker里可以开设多个vhost,用作不同用户的权限分离。
producer:消息生产者,就是投递消息的程序。
consumer:消息消费者,就是接受消息的程序。
channel:消息通道,在客户端的每个连接里,可建立多个channel,每个channel代表一个会话任务。
(2)客户端声明一个exchange,并设置相关属性。
(3)客户端声明一个queue,并设置相关属性。
(4)客户端使用routing key,在exchange和queue之间建立好绑定关系。
(5)客户端投递消息到exchange。
(1)exchange持久化,在声明时指定durable => 1
(2)queue持久化,在声明时指定durable => 1
(3)消息持久化,在投递时指定delivery_mode => 2(1是非持久化)
python客户端:
easy_install pika
RabbitMQ安装和配置的更多相关文章
- RabbitMQ学习系列(二): RabbitMQ安装与配置
上一篇,简单介绍了RabbitMQ的情况还有一些相关的概念,这一篇,会讲讲 RabbitMQ安装与配置. 1.安装 Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装RabbitM ...
- RabbitMQ(一):RabbitMQ 安装与配置(Mac)
一.rabbitmq 安装与配置 安装: brew install rabbitmq # 进入安装目录 cd /usr/local/Cellar/rabbitmq/3.7.12 # 启动 brew s ...
- 记一次RabbitMq 安装和配置坑
记一次RabbitMq 安装和配置坑 正常情况下安装 先安装erl ,在安装rabbitmq 这个在windows下的安装没什么技巧,按照默认一路下一步就ok.安装好后可以到cmd测试是否安装好. 测 ...
- SpringBoot(九)RabbitMQ安装及配置和使用,消息确认机制
Windows下RabbitMQ安装及配置地址: https://blog.csdn.net/zhm3023/article/details/82217222RabbitMQ(四)订阅模式:https ...
- windows RabbitMQ安装与配置
windows RabbitMQ安装与配置 1.安装Erlang 下载地址: http://www.erlang.org/downloads 注意: 右键以管理员身份进行安装,否则将导致后续无法启动 ...
- winddows rabbitmq安装与配置
RabbitMQ是一个在AMQP协议标准基础上完整的,可复用的企业消息系统.它遵循Mozilla Public License开源协议,采用 Erlang 实现的工业级的消息队列(MQ)服务器,Rab ...
- Rabbitmq安装与配置
install: 1.安装Erlang: $yum -y install erlang 2.安装rabbitmq-server: $rpm --import https://www.rabbitmq. ...
- Windows下RabbitMQ安装及配置
下载rabbitmq_server以及Erlang OTP平台 安装好了启动服务就行了 也可用命令 net start RabbitMQ 或 net stop RabbitMQ 配置用户添加环境变 ...
- rabbitmq 安装和配置
1.拉取镜像文件:docker pull centos 2.建立容器,且shell方式进入:docker run -it --name centos.rabbit centos /bin/bash 3 ...
随机推荐
- Ubuntu 16.04配置OpenCV 3.1.0 for Java
我们都知道,OpenCV是基于C++的开源计算机视觉库,但是从2.4.4版本开始提供了Java绑定,也就是说,我们也可以使用Java来开发基于OpenCV的计算机视觉应用.目前,最新的版本是3.1.0 ...
- Android 源码VecotorDrawable
1 R.styleable.VectorDrawable_viewportWidth 该资源的名字并非VectorDrawable_viewportWidth 而是 attrs.xml 下的声明 &l ...
- php入门变量之字符串
字符串只是一块用引号括起来的字符:字母.数字.空格.标点符号,等等. 下面列出的全都是字符串: 'Huige' "In watermelon sugar" '100' 'Augus ...
- Linux ps 命令获取查询结果中的单列信息
1.查看所有进程信息,但是只想获取COMMAND列的值 SDCxM-SDCAM-root-root> ps auxUSER PID %CPU %MEM VSZ RSS TT ...
- H264学习第一篇(编码结构分析)
学习H264之前,最好阅读一下维基百科中有关H264的相关介绍,里面包含了其的发展历程.主要特点.参考文献.参考网站等. 研究H264的主要文件包括两份参考手册(一份是语法结构参考手册,一份是JM开发 ...
- C# 读取oracle 中文乱码的解决方案
用OracleDataAccess.dll访问oracle数据库,遇到中文乱码的情况. 解决方案如下: 1查看字符集编码, 在数据库服务器端 启动 sqlplus SQL->select use ...
- nodejs的模块系统(实例分析exprots和module.exprots)
前言:工欲善其事,必先利其器.模块系统是nodejs组织管理代码的利器也是调用第三方代码的途径,本文将详细讲解nodejs的模块系统.在文章最后实例分析一下exprots和module.exprots ...
- android studio 打开github开源代码
1.最近下载的开源代码全是github来的,一直用eclipse开发,对于android studio来说是全新的 2.在eclipse导入一个工程那是so easy, import选择一下就可以. ...
- Kinetic使用注意点--collection
new Collection() 扩展了数组,主要用于配合new Container().get()使用 方法: each(func):遍历数组,执行回调函数.回调函数接收两个值,节点和索引. toA ...
- iOS 获取手机的型号,系统版本,软件名称,软件版本
转载自:http://www.2cto.com/kf/201210/162333.html 网上搜索出来的,记录下来以后使用方便: [java]//手机序列号 NSString* ide ...