Back to Home

AMQP is now also in PHP

type Introduction The 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 it. AMQP is used in servers ...

AMQP is now also in PHP

    type Introduction
    The 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 it.

    AMQP is used in queue servers: ZeroMQ , ActiveMQ , RabbitMQ .

    The advantage of RabbitMQ over other free software:
    - the protocol is more fully represented,
    - supports the cluster,
    - is implemented as a multi-threaded server, high performance

    The widespread use of AMQP in WEB development is constrained by two reasons: the lack of necessary skills (practice) in its use and low customer support. Basically, there are clients in c, java, python, c #. Great popularity of PHP in WEB development would be a pity to see your AMQP client.

    Currently, the following PHP clients have been developed:
    - php-amqplib The protocol is fully implemented in PHP. Personally, I could not start it, it hangs on the connection class with the AMQP broker. If anyone can launch it, I will be grateful if you share your experience.

    - php-amqp - Extension using the RabbitMQ-C client library . Only the ability to publish messages is implemented.

    - php-rabbit - Extension using the RabbitMQ-C client library hg.rabbitmq.com/rabbitmq-c . A protocol has been implemented in sufficient use for practice. It is developed and supported by me, so I am ready for a constructive dialogue.

    After introducing 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 Samovsky

    Address of the group http://groups.google.com/group/rabbitmq_rus Those wishing to join Wellcome !!!
    Usage example: Epilogue type The following post will be devoted to practical application and expansion features
    // 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 );
    }


    Read Next