php操作kafka - saintdingtheGreat - 博客园


本站和网页 https://www.cnblogs.com/saintdingspage/p/11361524.html 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

php操作kafka - saintdingtheGreat - 博客园
首页
新闻
博问
专区
闪存
班级
我的博客
我的园子
账号设置
简洁模式 ...
退出登录
注册
登录
saintdingtheGreat
博客园
首页
新随笔
联系
管理
订阅
php操作kafka
php操作kafka----可以参照网上的安装步骤,先安装ldkafka rdkafka,然乎启动zookeeper和kafka服务器
<?php
//$conf = new Rdkafka\Producer();
//$producer = new RdKafka\Producer();
class kafka
public $broker_list="localhost:9092";
public $topic = "wuwa";
public $partion = 0;
protected $producer = null;
protected $consumer = null;
public function __construct()
$rk = new RdKafka\Producer();
if(empty($rk))
throw new \Exception("producer error");
$rk->setLogLevel(LOG_DEBUG);
if(!$rk->addBrokers($this->broker_list))
throw new \Exception('添加broker失败');
$this->producer=$rk;
public function sendmsg($array_message="")
/*$topic = $this->producer->newTopic($this->topic);
return $topic->produce(RD_KAFKA_PARTITION_UA,$this->partion,json_encode($array_message));*/
$topic = $this->producer->newTopic($this->topic);
return $topic->produce(RD_KAFKA_PARTITION_UA,$this->partion,$array_message);
$kafuka = new Kafka();
$kafuka->sendmsg('general! welcome to distributed world!');
$kafuka->sendmsg('好好学编程,泡昌仔和劲儿弟弟!');
输出结果
general! welcome to distributed world!好好学编程,泡昌仔和劲儿弟弟!
posted @
2019-08-16 02:24
saintdingtheGreat
阅读(2323)
评论(0)
编辑
收藏
举报
刷新评论刷新页面返回顶部
Copyright 2022 saintdingtheGreat
Powered by .NET 7.0 on Kubernetes