• 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!
好好学编程,泡昌仔和劲儿弟弟!

最新文章

  1. Android 开发环境搭建以及工具(不断更新)
  2. AngularJS开发之_指令
  3. Run same command on all SQL Server databases without cursors
  4. Linux ethtool命令
  5. visual studio 2013连接Oracle 11g并获取数据:(一:环境搭建)
  6. 洛谷P1113 杂物
  7. ORA-01034: ORACLE not available
  8. telnet测试端口号
  9. MyBatis深入理解一
  10. Python重写C语言程序100例--Part6
  11. R语言高性能编程(二)
  12. Android 超高仿微信图片选择器 图片该这么加载
  13. Do You Kown Asp.Net Core -- Asp.Net Core 2.0 未来web开发新趋势 Razor Page
  14. 初学高级程序设计 shell编程
  15. [CocoaPods]Podfile文件
  16. MySql习题和答案
  17. javascript中所有函数的参数都是按值传递的
  18. C++的那些事 1
  19. centos配置DNS和ip
  20. Python学习笔记:startswith &amp; endswith 判断开头结尾是否为指定字符串

热门文章

  1. [学习笔记] Hibernate 4.3.5 下载与安装
  2. Javascript性能优化阅读笔记
  3. Linux上面mount 域控的目录 超时 然后提示 error的解决办法
  4. Equations HDU - 1496(哈希的应用)
  5. 解决python无法安装mysql数据库问题
  6. windows系统 MySQL8.0.12详细安装步骤及基本使用教程
  7. Idea加载项目扫描完毕后自动退出
  8. css鼠标悬浮控制元素隐藏与显示
  9. windows连接远程服务器报错&#39;SSH&#39; 不是内部或外部命令,也不是可运行的程序 或批处理文件 解决方案
  10. bootstrap-selectpicker 插件事件