RabbitMQ is an open-source enterprise-level message system based on AMQP (AdvancedMessageQueuingProtocol) and has high reliability. It is currently used by many websites, including reddit and Poppen.de. 1. Install RabbitMQsudoapt-getinstallrabbitmq-serversudo/etc/init. d/rabbitmq-serverstart in Ubuntu
RabbitMQ is an open-source enterprise-level Message system based on AMQP (Advanced Message Queuing Protocol) and has high reliability. It is currently used by many websites, including reddit and Poppen.de.
1. Install RabbitMQ in Ubuntu
Sudo apt-get install rabbitmq-server
Sudo/etc/init. d/rabbitmq-server start
2. Install librabbitmq
Sudo apt-get install mercurial
Hg clone http://hg.rabbitmq.com/rabbitmq-c
Cd rabbitmq-c
Hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen
Autoreconf-I &./configure & make & sudo make install
3. install php-rabbit Extension
Wget http://php-rabbit.googlecode.com/files/php-rabbit.r91.tar.gz
Tar-zxvf php-rabbit.r91.tar.gz
Cd php-rabbit.r91
/Path/to/php/bin/phpize
./Configure-with-amqp-with-php-config =/path/to/php/bin/php-config
Make & sudo make install
Edit php. ini to add:
Extension = rabbit. so
Output phpinfo to check whether the extension has been loaded successfully. have fun :)
4. Demo program
Producer:
/** * producer demo * * @author wei * @version $Id$ **/$params = array('host' =>'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";}} ?>