type introductionThe
AMQP protocol was well described in
AMQP articles
in Russian ,
RabbitMQ: Introduction to AMQP AMQP is a practice of use and I would not like to repeat.
AMQP is used in queue servers:
ZeroMQ ,
ActiveMQ ,
RabbitMQ .
RabbitMQ advantage over other free software:
- the protocol is more fully presented,
- supports cluster,
- implemented as a multi-threaded server, high performance
')
The wide distribution of AMQP in WEB development is hampered by two reasons: the lack of the necessary skills (practice) of its use and small customer support. Basically there are clients in languages c, java, python, c #. The great popularity of PHP in the WEB development would also have seen its AMQP client.
The following PHP clients are currently running:
-
php-amqplib The protocol is implemented in full enough in PHP. I personally failed to launch it, it hangs on the connection class with AMQP broker. If anyone can run it, I will be grateful if you share your experience.
-
php-amqp - An extension that uses the
RabbitMQ-C client library. Implemented only the ability to post messages.
-
php-rabbit - Extension that uses the RabbitMQ-C client library
hg.rabbitmq.com/rabbitmq-c . Implemented a protocol sufficient for practice use. It develops and is supported by me, so I am ready for a constructive dialogue.
After the presentation of PHP Rabbit to the RabbitMQ community, they made an offer to the Russian-speaking RabbitMQ Community to create their own Russian-speaking discussion group, which includes one of the RabbitMQ developers -
Dmitry SamovskyGroup address http://groups.google.com/group/rabbitmq_rus Those who want to join Wellcome !!!
Example of use:// queue declare queue.php
$rabbit = new Rabbit(); // default connection localhost:5672
//user=guest psw=guets vhost="/"
$rabbit->queue("q_test"); // declare queue "q_test"
// queue declare queue2.php
$rabbit = new Rabbit(); // connection
$rabbit->queue("q_test2"); // declare queue "q_test2"
// exchange declare exchange.php
$rabbit = new Rabbit(); // connection
$rabbit->exchange('e_test', "topic"); // topic exchange declare
$rabbit->bind('e_test','q_test','key_test.t1'); // bind exchange to queue "q_test" by key="key_test"
$rabbit->bind('e_test','q_test2','key_test.t2'); // bind exchange to queue "q_test2" by key="key_test2"
// publishing to queue1 publish.php
$msg = array(
'message1','message2','message3','message4'
);
$rabbit = new Rabbit(); // connection
foreach ( $msg as $item ) // // publishing to queue1
$rabbit->publish('e_test','key_test.t1',$item);
// publishing to queue2
foreach ( $msg as $item ) // // publishing to queue2
$rabbit->publish('e_test','key_test.t2',$item."01");
// reading all messages from queue: consume.php
$rabbit = new Rabbit(); // connection
$count=$rabbit->queue("q_test");
$res =$rabbit->consume("q_test", $count)
var_dump($res);
// $res is array of messages;
// reading some messages from queue: queueItems.php
$rabbit = new Rabbit(); // connection
$count=$rabbit->queue("q_test2");
for ( $i=0; $i<$count;$i++ ){
$res = $rabbit->queueItem("q_test2" );
print_r( $res );
}
Epilogue typeThe next post will be devoted to the practical application and features of the expansion