# Kafka
Kafka用于Kafka服务的管理,提供消费者和成产者客户端。服务器需要安装[librdkafka](https://github.com/edenhill/librdkafka),PHP需要安装[rdkafka](https://github.com/arnaud-lb/php-rdkafka)扩展。
#### 生产者
```PHP
/**
* 创建生产者对象
* /
$producer = new Producer([
//kafka实例地址,多个地址用逗号间隔
'broker_list' => '127.0.0.1:9092',
//kafka日志级别
'log_level' => LOG_DEBUG
]);
/**
* 创建话题
*/
$topic = $producer->topic(string $topic = '', TopicConf $topicConf = null);
/**
* 生产消息
*/
$topic->produce(string $message = '');
```
#### 低级消费者
```PHP
/**
* 创建消费者者对象
* /
$consumer = new Consumer([
//kafka实例地址,多个地址用逗号间隔
'broker_list' => '127.0.0.1:9092',
//topic分页
'partition' => 0,
// kafka日志级别
'log_level' => LOG_DEBUG
]);
/**
* 消费者者选取消费话题
* /
$topic = $consumer->topic(string $topic = '', TopicConf $topicConf = null);
/**
* 消费者消费消息
* /
$topic->consume(callable $callback = null, int $timeout = 120e3);
```
#### 高级消费者
```PHP
/**
* 创建消费者者对象
* /
$consumer = new GroupConsumer([
//kafka实例地址,多个地址用逗号间隔
'broker_list' => '127.0.0.1:9092',
//消费者分组
'group_id' => 0,
// 消费等待时间
'timeout' => 120e3
]);
/**
* 消费者消费消息
* /
$consumer ->consume(array $topics = [], callable $callback = null);
```