PHP AMQP RABBITMQ Introduction and use

Source: Internet
Author: User
Tags message queue rabbitmq

AMQP, the advanced message Queuing Protocol, an application-layer standard premium Messaging queuing protocol that provides unified messaging services, is an open standard for application-layer protocols designed for message-oriented middleware. The client and message middleware based on this protocol can deliver the message, and it is not restricted by the different products of client/middleware, different development language and other conditions. The implementations in Erlang are RABBITMQ and so on.

RabbitMQ is an open-source implementation of AMQP (advanved Message Queue) developed by Erlang.

Several concept notes:

Broker: The Message Queuing server entity is simply the case. Exchange: A message switch that specifies what rules the message is routed to and to which queue. Queue: A message queue carrier in which each message is put into one or more queues. Binding: Bind, which is the role of binding exchange and queue according to routing rules. Routing key: The routing keyword, exchange messages are delivered based on this keyword. Vhost: Virtual host, a broker can open multiple vhost, as a separate user permissions. Producer: The message producer is the program that delivers the message. Consumer: The message consumer is the program that receives the message. Channel: The message channels, in each connection of the client, multiple channels can be established, each channel represents a session task.

The use of Message Queuing is probably as follows:

(1) The client connects to the Message Queuing server and opens a channel. (2) The client declares an exchange and sets the related properties. (3) The client declares a queue and sets the related properties. (4) The client uses routing key to establish a good binding relationship between Exchange and queue. (5) Clients post messages to exchange.
(6) When Exchange receives a message, the message is posted to one or more queues

In PHP, the AMQP extension provides several classes and a series of methods to help us accept and send messages

Function class

Amqpchannel A connection connection can establish multiple channel, which can be understood as a logical connection
Amqpconnection refers to a physical connection, a client and a server have a connection between
Amqpenvelope Message Pack
Amqpexchange Message Switch
Amqpqueue queue

Exception class

Amqpexception
Amqpqueueexception
Amqpconnectionexception
Amqpchannelexception
Amqpexchangeexception

Create a connection

1new amqpconnection (array(2     ' host ' = ' example.host ', 3     ' Vhost ' = + '/',4     ' port ' = 5763,5     ' login ' = ' user ',6     ' Password ' = ' password '7 );

Create Channel

1 $channel New Amqpchannel ($connection);

Create a switch

1 $exchange New Amqpexchange ($channel); 2 $exchange->setname ($e3$exchange, _name,setType //  4$exchange// Persistence

PHP AMQP RABBITMQ Introduction and use

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.