\r\n 123\r\n ABC\r\n"); use RdKafka\Conf; use RdKafka\Producer; class MyProducer extends Producer { public function __construct($cfg) { parent::__construct($cfg); } public function send($topicname, $key, $payload) { $topic = $this->newTopic($topicname); $topic->produce(RD_KAFKA_PARTITION_UA, 0, (string)$payload, (string)$key); // note: both key and payload need to be strings } } $cfg = new Conf(); $cfg->set('bootstrap.servers', SERVER); $sender = new MyProducer($cfg); for($i = 0; $i < 3; $i++) { $sender->send(TNAME, $i, PAYLOAD); } ?>