#Kafka工具库

###旧版本使用示例（KafkaProducer has been DEPRECATED）
```php
$service = KafkaProducer::getInstance();
$message= json_encode(array('test' => 'kafka produce', 'reason' => 'send message'), JSON_UNESCAPED_UNICODE);
var_dump($service);
$service->produce('10.120.25.19:9092,10.120.24.27:9092,10.120.25.6:9092', 'push_content_sync', $message);
```

###新版本使用示例
```php
    public function kafkaAction()
    {
        $topicName = 'topicA';
        $setConfDrMsgCb = function ($kafka, \RdKafka\Message $message) {
            echo '打印消息:' . "\n";
            var_export($message);
            echo "\n";
            if($message->err){
                //@todo 生产失败的逻辑处理
            } else{
                //@todo 生产成功的逻辑处理
            }
        };
        $setErrorCbCallback = function ($kafka, $err, $reason) {
            echo sprintf("setErrorCb (error_ori:%s)(error: %s) (reason: %s)", $err, rd_kafka_err2str($err), $reason);
        };
        // $kafka = KafkaUtil::getInstance('test', ['context' => ['contextArr']]);
        // $ret = $kafka->produce('eee');
        $brokers = '127.0.0.1:9092';
        $kafka = KafkaUtil::getInstance();
        $ret = $kafka->setBrokers($brokers)->setTopicName('topicA')->produce('ccc');
        var_dump($kafka);
        exit;
        //设置brokers-支持数组或者字符串
        $kafka->setBrokers($brokers)
            //设置topic
            ->setTopicName($topicName)
            //setConfDrMsgCb--设置生产消息失败与成功的回调,默认初始化时会调用该事件,如果自定义后就会覆盖默认的
            ->setConfDrMsgCb($setConfDrMsgCb)
            //setConfErrorCb--设置错误回调,如若不设置默认会走默认逻辑
            ->setConfErrorCb($setErrorCbCallback)
            //支持连贯用法生产多条数据并且是不同的topic
            ->run('message111', $topicName);
    }
```



