Message Queue: amqp and Ubuntu installation command (APT-Get)

Source: Internet
Author: User
Tags rabbitmq

(1) Basic Concepts

Rabbitmq is a popular open-source message queue system developed in Erlang. I used to be very interested in this language. I learned it for a while and didn't stick to it later. Rabbitmq is the standard implementation of amqp (Advanced Message Queue Protocol. If you are not familiar with amqp, it is difficult to directly read the document of rabbitmq. However, it only has several key concepts. Here is a brief introduction.

The structure of rabbitmq is as follows:

Several concepts:

BROKER: the entity of the Message Queue Server.

Exchange: the message switch, which specifies the rules of the message and the queue to which the message is routed.

Queue: Message Queue carrier. Each message is put into one or more queues.

Binding: binding. It binds exchange and Queue according to routing rules.

Routing key: The route keyword. Exchange ships messages based on this keyword.

Vhost: Virtual Host. Multiple vhosts can be opened in a broker to separate permissions of different users.

Producer: the producer of a message.Program.

Consumer: the message consumer, which is the program that receives the message.

Channel: Message Channel. Multiple channels can be created in each connection of the client. Each channel represents a session task.

The procedure of using a message queue is as follows:

(1) The client connects to the Message Queue Server and opens a channel.

(2) The client declares an exchange and sets related attributes.

(3) The client declares a queue and sets related attributes.

(4) The client uses the routing key to establish a binding relationship between exchange and queue.

(5) The client delivers the message to exchange.

After receiving a message, exchange routes the message to one or more queues based on the key and binding of the message.

There are also several types of exchange, which are completely shipped Based on keys called direct switches. For example, if the routing key is set to "ABC" during binding, the messages submitted by the client, only when the key is set to "ABC" Will it be delivered to the queue. After the key is matched in a pattern, the shipping is called a topic switch. The symbol "#" matches one or more words, and the symbol "*" matches the correct word. For example, "ABC. #" matches "ABC. Def. Ghi" and "ABC. *" only matches "ABC. Def ". The fanout switch does not need a key. It adopts the broadcast mode. When a message comes in, it is delivered to all the queues bound to the switch.

Rabbitmq supports message persistence, that is, writing data on a disk. For the sake of data security, I think most users will choose persistence. Message Queue persistence consists of three parts:

 

(1) Exchange persistence, specifying durable => 1 during Declaration

(2) queue persistence, specifying durable => 1 during Declaration

(3) Message persistence. Specify delivery_mode => 2 (1 is non-persistent) during delivery)

If exchange and queue are both persistent, the binding between them is also persistent. If exchange and queue are both persistent and non-persistent, binding cannot be established.

(2) Installation

1. Install rabbitmq in Ubuntu

Sudo apt-Get install rabbitmq-Server
Sudo/etc/init. d/rabbitmq-Server start

2. Install librabbitmq

Sudo apt-Get install mercurial
Hg clone http://hg.rabbitmq.com/rabbitmq-c
CD rabbitmq-C
Hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen
Autoreconf-I &./configure & make & sudo make install

2. install PHP-amqp

Download the PHP-amqp source code package

Tar xzvf amqp-0.0.7.tgz

3. download the patch issue2.patch2

Patch-D amqp-0.0.7 <issue2.patch2
CD amqp-0.0.7
Phpize./configure -- With-amqp make sudo make install

4. Edit PHP. ini to add

Extension = amqp. So
Output phpinfo to check whether the extension has been loaded successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.