/** * 生产初始化 * @param string $configKey * @throws Exception */ function getProductInstance($configKey = "default") { $configObj = new Config("kfk"); $config = $configObj->get($configKey); try { $rk = new \RdKafka\Producer(); $rk->setLogLevel(LOG_DEBUG); $rk->addBrokers($config); $this->rk = $rk; $this->type = 0; } catch (\Exception $e) { throw new \Exception($e->getMessage()); } }
<?php $rk = new RdKafka\Producer(); $rk->setLogLevel(LOG_DEBUG); $rk->addBrokers("127.0.0.1"); $topic = $rk->newTopic("test"); $topic->Producer(RD_KAFKA_PARTITION_UA, 0, "Message payload");