zoukankan      html  css  js  c++  java
  • 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);
    }
    ?>
  • 相关阅读:
    Arduino学习笔记10
    Arduino学习笔记07
    Arduino学习笔记6
    Arduino学习笔记5
    Arduino学习笔记4
    Arduino学习笔记3
    linux下库文件的编程
    学习编程语言究竟学什么
    Arduino学习笔记2---数字温度计
    Arduino学习笔记0---开发板的了解
  • 原文地址:https://www.cnblogs.com/appledady/p/9322736.html
Copyright © 2011-2022 走看看