PHP基础组件-Zookeeper+MetaQ

1.Zookeeper扩展安装

wget http://mirror.bit.edu.cn/apache//zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz 
tar –zxvf zookeeper-3.4.6.tar.gz 
cd /usr/local/src/zookeeper-3.4.6/src/c 
./configure && make && make install 

wget http://pecl.php.net/get/zookeeper-0.2.2.tgz 
tar -zxvf zookeeper-0.2.2.tgz 
cd zookeeper-0.2.2 
/data/php/bin/phpize 
./configure --with-php-config=/data/php/bin/php-config 
make && make install 

vim /data/php/etc/php.ini 
extension=zookeeper.so 
#重启PHP即可

2.消费MetaQ

<?php
require_once 'MetaQ.php';

$metaqConfig['group'] = 'Flyme_BBS_TEST';
$metaqConfig['topic'] = 'FlYME_USER_UC';
$metaqConfig['config'] = array('zkHosts' => '172.16.200.239:2181,172.16.200.233:2181,172.16.200.234:2181');


$metaq = new MetaQMetaQ($metaqConfig['config']);
$metaq->subscribe($metaqConfig['topic'], $metaqConfig['group']);
while (1) {
    $msgs = $metaq->getNext();
    foreach ($msgs as $msg) {
        print_r($msg);
        usleep(1000);
    }
}
?>

3.写MetaQ

<?php
require_once 'MetaQ.php';

$metaqConfig['group'] = 'Flyme_BBS_TEST';
$metaqConfig['topic'] = 'FlYME_USER_UC';
$metaqConfig['config'] = array('zkHosts' => '172.16.200.239:2181,172.16.200.233:2181,172.16.200.234:2181');


$metaq = new MetaQMetaQ($metaqConfig['config']);
$metaq->initPartitionList($metaqConfig['topic']);

$i = 0;
while (++$i < 10000) {
    $result = $metaq->put('t1', 'hello' . $i);
    print_r($result);
    usleep(1000);
}
?>
原文地址:https://www.cnblogs.com/appledady/p/9322736.html