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