php-rdkafka测试笔记

4-09 350 views

参考:https://learnku.com/articles/15176/laravel-implementation-of-kafka-message-push-and-receive-processing

安装

安装librdkafka 库
git clone https://github.com/edenhill/librdkafka.git
./configure
make
sudo make install
安装rdkafka
sudo pecl install rdkafka
配置扩展到php.ini
extension=rdkafka.so

测试

<?php
#写代码测试
$conf = new \RdKafka\Conf();
// enable debug mode
$conf->set('log_level', LOG_DEBUG);
$conf->set('debug', 'all');
$rk = new \RdKafka\Producer($conf);
$rk->addBrokers("192.168.5.170:9092,192.168.5.99:9092");

$topic = $rk->newTopic("php_topic");

$topic->produce(RD_KAFKA_PARTITION_UA, 0, "Message payload");

$producer = new \RdKafka\Producer();
$producer->addBrokers("192.168.5.170:9092,192.168.5.99:9092");

$obj_topic = $producer->newTopic("php_topic");

//
$input_handler = fopen('php://stdin', 'r');

while (true) {
    echo "\nPlease input  messages:\n";
    $payload = trim(fgets($input_handler));

    // empty message will be quit
    if (empty($payload)) {
        break;
    }

    // send message
    $obj_topic->produce(RD_KAFKA_PARTITION_UA, 0, $payload);
}

echo "done\n";
exit(0);

使用方法

https://www.jianshu.com/p/e4bc3f56354d

php使用Carbon获取2个日期之间的日期

<?php use Carbon\CarbonPeriod; $period = CarbonPeriod::create('2018-06-14', '2018-06-20'); // Iterate over the period fore...

阅读全文

php 解决超卖的几种方案(redis锁、mysql悲观锁)

1.创建商品和订单表模拟商品交易操作 fa_goods商品表,stock商品库存,test_order=订单表 2.添加一个测试商品数据(商品数量为150个) 测试并发购买的方法(gol...

阅读全文

centos8 yum安装php7.3

执行命令 $ yum install epel-release $ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm $ dnf install -y https://rpms...

阅读全文

欢迎留言