生活随笔
收集整理的這篇文章主要介紹了
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!
好好學編程,泡昌仔和勁兒弟弟!
轉載于:https://www.cnblogs.com/saintdingspage/p/11361524.html
總結
以上是生活随笔為你收集整理的php操作kafka的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。