php操作kafka
2024-09-05 08:03:33
- 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!
好好学编程,泡昌仔和劲儿弟弟!
最新文章
- Android 开发环境搭建以及工具(不断更新)
- AngularJS开发之_指令
- Run same command on all SQL Server databases without cursors
- Linux ethtool命令
- visual studio 2013连接Oracle 11g并获取数据:(一:环境搭建)
- 洛谷P1113 杂物
- ORA-01034: ORACLE not available
- telnet测试端口号
- MyBatis深入理解一
- Python重写C语言程序100例--Part6
- R语言高性能编程(二)
- Android 超高仿微信图片选择器 图片该这么加载
- Do You Kown Asp.Net Core -- Asp.Net Core 2.0 未来web开发新趋势 Razor Page
- 初学高级程序设计 shell编程
- [CocoaPods]Podfile文件
- MySql习题和答案
- javascript中所有函数的参数都是按值传递的
- C++的那些事 1
- centos配置DNS和ip
- Python学习笔记:startswith &; endswith 判断开头结尾是否为指定字符串
热门文章
- [学习笔记] Hibernate 4.3.5 下载与安装
- Javascript性能优化阅读笔记
- Linux上面mount 域控的目录 超时 然后提示 error的解决办法
- Equations HDU - 1496(哈希的应用)
- 解决python无法安装mysql数据库问题
- windows系统 MySQL8.0.12详细安装步骤及基本使用教程
- Idea加载项目扫描完毕后自动退出
- css鼠标悬浮控制元素隐藏与显示
- windows连接远程服务器报错&#39;SSH&#39; 不是内部或外部命令,也不是可运行的程序 或批处理文件 解决方案
- bootstrap-selectpicker 插件事件