PHPackages                             abbots/yii2-kafka - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. abbots/yii2-kafka

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

abbots/yii2-kafka
=================

The kafka integration for the Yii framework

v1.2(5y ago)64963[1 issues](https://github.com/abbots/yii2-kafka/issues)BSD-3-ClausePHPPHP &gt;=7.0.0

Since Sep 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/abbots/yii2-kafka)[ Packagist](https://packagist.org/packages/abbots/yii2-kafka)[ RSS](/packages/abbots-yii2-kafka/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Yii2集成kafka扩展
=============

[](#yii2集成kafka扩展)

Requirements
------------

[](#requirements)

1、 Yii2框架

2、 RdKafka扩展，扩展安装如下

```
1、安装librdkafka

git clone https://github.com/edenhill/librdkafka.git
cd librdkafka
./configure
make && make install

2、安装php-rdkafka扩展

git clone https://github.com/arnaud-lb/php-rdkafka.git
cd php-rdkafka
phpize
./configure --with-php-config=/usr/local/php7.0/bin/php-config
make && make install

3、php.ini配置

extension = rdkafka.so

```

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require abbots/yii2-kafka

```

DIRECTORY STRUCTURE
-------------------

[](#directory-structure)

```
src
    Kafka
    ConsumerInterface
    Consumer
    RdConfig
    Logger

```

Config
------

[](#config)

```
components => [
    'example' => [
        'class' => yii\kafka\Consumer::class,
        'group_id' => 'group_example',       //消费组
        'topics'   => ['topic_example'],     //消费主题

        /*---------------RdKafka配置------------------------*/
        'enable_auto_commit' => 0,          //是否自动提交[1打开、0关闭]，默认关闭
        'auto_offset_reset' => 'smallest',  //数据下标模式
        /*---------------RdKafka配置------------------------*/

        //消费回调类配置
        'callback' => [
            'class' => \console\service\KafkaService::class,
            'businessMethod' => 'business',
        ],

        'exceptionNoticeClass' => \common\components\kafka\ExceptionNotice:class

        //broker节点配置
        //kafkaBrokerList:192.168.0.1:9092,192.168.0.2:9092,192.168.0.3:9092
        'broker_list' => function(){
            return Yii::$app->params['kafkaBrokerList'];
        },
    ],
]

```

Example
-------

[](#example)

业务逻辑类封装(必须实现yii\\kafka\\ConsumerInterface接口)

```
