RabbitMQ php 施用

來源:互聯網
上載者:User
RabbitMQ php 使用

RabbitMQ是一個開源的基於AMQP(Advanced Message Queuing Protocol)標準,並且可靠性高的企業級訊息系統,目前很多網站在用,包括reddit,Poppen.de等。

1. 安裝RabbitMQsudo apt-get install rabbitmq-serversudo /etc/init.d/rabbitmq-server start

?

?

?

2. 安裝librabbitmqsudo apt-get install mercurialhg clone http://hg.rabbitmq.com/rabbitmq-ccd rabbitmq-chg clone http://hg.rabbitmq.com/rabbitmq-codegen codegenautoreconf -i && ./configure && make && sudo make install3. 安裝php-rabbit擴充wget http://php-rabbit.googlecode.com/files/php-rabbit.r91.tar.gztar -zxvf php-rabbit.r91.tar.gzcd php-rabbit.r91/path/to/php/bin/phpize./configure –with-amqp –with-php-config=/path/to/php/bin/php-configmake && sudo make install編輯 php.ini 添加:extension=rabbit.so輸出phpinfo看下是否擴充已經載入成功,have fun:)

?

?

?

'localhost',                'port' => 5672,                'login' => 'guest',                'password' => 'guest',                'vhost' => '/');$cnn = new AMQPConnect($params); // declare Exchange$exchange = new AMQPExchange($cnn);$exchange->declare('ex1', 'topic', AMQP_DURABLE ); // declare Queue$queue = new AMQPQueue($cnn);  $queue->declare('queue1', AMQP_DURABLE);  // bind Queue$queue->bind('ex1','wei.#'); // publishing$msg = "msg"; for ($i=0; $i < 100; $i++) {     $res = $exchange->publish($i . 'msg', 'wei.' . $i);    if ($res) {        echo $i . 'msg' . " Yes\n";    } else {        echo $i . 'msg' . " No\n";    }} ?>consumer:?View Code PHP'localhost',                'port' => 5672,                'login' => 'guest',                'password' => 'guest',                'vhost' => '/');$cnn = new AMQPConnect($params); // create the Queue$queue = new AMQPQueue($cnn, 'queue1');$queueMessages = $queue->consume(100); foreach($queueMessages as $item) {    echo "$i.$item\n";}?>

?

?

?

參考:
http://www.rabbitmq.com/install.html
http://blog.ftofficer.com/2010/03/translation-rabbitmq-python-rabbits-and-warrens/
http://code.google.com/p/php-rabbit/

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.