1. Introduction
MQ is all called the message queue, and Message Queuing (MQ) is an application-to-application communication method. Applications communicate by reading and writing messages to and from the queue (data for the application), without requiring a dedicated connection to link them. Message passing refers to the process of communicating between programs by sending data in a message, rather than by directly invoking each other, and directly invoking techniques such as remote procedure calls.
As shown in the following:
1.Server (Broker): A process that accepts client connections to implement AMQP Message Queuing and routing capabilities.
2.Virtual Host: is actually a virtual concept, similar to the rights control group, a virtual host can have a number of exchange and queue, but the minimum granularity of permissions control is virtual host
3.Exchange: Accepts messages sent by the producer and routes messages to queues in the server according to the binding rules. ExchangeType determines the behavior of Exchange routed messages, for example, in RABBITMQ, where ExchangeType has direct, fanout, and topic three, different types of exchange routes behave differently.
4. Messagequeue: Messages queued to store messages that have not yet been consumed by consumers.
5.Message: Consists of header and body, header is a collection of various attributes added by the producer, including whether the message is persisted, which message queue is accepted, what priority is, and so on. The body is the app data that really needs to be transferred.
6.Binding:binding contacted.Exchange andMessage Queue.Exchange is associated with multiplemessage queue occurs binding will generate a route table, the routing table stores message queue required to eliminate restrictions are binding Key. When exchange received message will resolve its header get Routing key,exchange according to routing Key and exchange type will message route to message Queue. binding Key by consumer in binding exchange with message queue when specified, while routing key sent by producer message when specified, both are matched by exchange Type determines.
7.Connection: Connection, for RABBITMQ, is actually a TCP connection between the client and broker.
8.Channel: Channel, the client cannot send a message only after the client-to-broker connection has been created. You need to create a CHANNEL,AMQP protocol for each connection to specify that only the channel can execute AMQP commands. A connection can contain multiple channel. The channel is required because TCP connection creation and release are very expensive, if a client each thread needs to interact with the broker, if each thread to establish a TCP connection, regardless of whether the TCP connection is wasted, even if the operating system can not afford to build every second This many TCP connections. RABBITMQ recommended between client threads To share the channel, at least to ensure that the thread sending messages for the shared channel must be serial, it is recommended that connection be shared as much as possible.
9.COMMAND:AMQP, the client implements its own logic by command to complete the interaction with the AMQP server. For example, in RABBITMQ, a client can send a message through the Publish command, Txselect open a transaction, and Txcommit commit a transaction.
2. Features and application scenarios
MQ is a typical representative of the consumer-producer model, where one end writes messages to the message queue , while the other end reads or subscribes to messages in the queue. MQ is similar to JMS , but the difference is that JMS is a standard and API definition for the Sun JAVA messaging middleware service, and MQ follows the specific implementations and products of the AMQP protocol.
In the project, some operations without immediate return and time-consuming are extracted and processed asynchronously , which greatly saves the request response time of the server and improves the throughput of the system.
3. Installation
RABBITMQ is based on Erlang, so you must first configure the Erlang environment.
Download the latest Erlang installation package from Erlang's official website http://www.erlang.org/download.html, the version i downloaded is otp_src_R14B03.tar.gz.
And then:
$ tar xvzf otp_src_R14B03.tar.gz
$ CD OTP_SRC_R14B03
$./configure
The compiled output is as follows:
Hint no wxwidgets and FOP, but the problem is not big. Go on:
$ make
$ sudo make install
After installing Erlang, start installing Rabbitmq-server.
Main references official documents:http://www.rabbitmq.com/build-server.html
A newer version of Python needs to be installed. Install slightly.
Need to install Simplejson. Download the latest version from here: http://pypi.python.org/pypi/simplejson#downloads . The version I downloaded is simplejson-2.2.1.tar.gz
$ tar xvzf simplejson-2.2.1.tar.gz
$ CD simplejson-2.2.1
$ sudo python setup.py install
Then install RABBITMQ Server. Download the source code version of RABBITMQ: http://www.rabbitmq.com/server.htmlfrom here. The version I downloaded is rabbitmq-server-2.6.1.tar.gz
$ tar xvzf rabbitmq-server-2.6.1.tar.gz
$ CD rabbitmq-server-2.6.1
$ make
# target_dir=/usr/local Sbin_dir=/usr/local/sbin Man_dir=/usr/local/man make install
There are three commands in the sbin/directory:
Rabbitmqctl rabbitmq-env Rabbitmq-server
The installation was successful.
Run
Locate the sbin/directory and run the program:
/usr/local/sbin/rabbitmq-server–detached
Stop program:
/usr/local/sbin/rabbitmqctl stop
rabbitmq--Quick Start