PHPackages                             dnkfk/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. dnkfk/yii2-kafka

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

dnkfk/yii2-kafka
================

kafka client for yii2

v0.1.0(1y ago)216MITPHPPHP &gt;=7.4

Since Oct 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/DinoHe/yii2-kafka)[ Packagist](https://packagist.org/packages/dnkfk/yii2-kafka)[ RSS](/packages/dnkfk-yii2-kafka/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

**Requirements**

1、yii2

2、php &gt;= 7.4

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

```
    通过git源码编译安装：

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

    安装php-rdkafka扩展：
    git clone https://github.com/arnaud-lb/php-rdkafka.git
    cd php-rdkafka
    phpize
    ./configure --with-php-config=/usr/local/php7.4/bin/php-config
    make && make install

    ubuntu系统环境下安装：

    sudo apt-get install librdkafka-dev
    pecl install rdkafka

    php.ini配置：
    extension = rdkafka.so

```

kafka服务使用docker镜像文件构建，示例：tmp-docker-compose.yml

**yii2使用kafka**

```
 composer require dnkfk/yii2-kafka

```

**消费者组件配置**

component/kafka.php

```
    return [
        'class'   => \Dnkfk\KafkaConnection::class,
        'conn'    => ['localhost:9092'], //连接主机配置
        'topics'  => ['test_topic'], //所有需要订阅的主题
        'binding' => [
            [
                'consumer' => 'test_consumer', //消费者名称
                'group'    => 'test_group', //消费组
                'topics'   => ['test_topic'], //订阅主题
                'callback' => TestConsumer::class, //消费者回调
            ]
        ]
    ];
```

**发布消息到主题代码示例**

直接发布消息

```
    $msg = ['msg' => 'test']; //$msg可以是数组或字符串
    \Yii::$app->kafka->produce($msg, 'test_topic');
```

批量发布消息

```
    //构建生产者主题
    $producer = \Yii::$app->kafka->getProducer('test_topic');
    //批量发布消息到主题
    for ($i = 0; $i < 10; $i++) {
        $producer->produceMsg("message {$i}");
    }
    //等待消息全部发布完成
    $producer->wait();
```

**启动消费者**

```
php yii kafka/consume test_consumer

```

**消费者消费代码示例**

```
    use Dnkfk\ConsumerInterface;
    use Dnkfk\Message;

    class TestConsumer implements ConsumerInterface
    {

        /**
         * 执行消费
         *
         * @param Message $message
         * @return void
         */
        public function execute(Message $message)
        {
            $payload = json_decode($message->getPayload(), true);

            var_dump($payload); //输出：['msg' => 'test']
        }
    }
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

580d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/446ff6f7303ef77a9fda2b0f81c997855af4c18e17fbc6417004b6fccbddc73c?d=identicon)[DinoHe](/maintainers/DinoHe)

---

Top Contributors

[![DinoHe](https://avatars.githubusercontent.com/u/45335214?v=4)](https://github.com/DinoHe "DinoHe (1 commits)")

---

Tags

yii2kafkayii2-kafka

### Embed Badge

![Health badge](/badges/dnkfk-yii2-kafka/health.svg)

```
[![Health](https://phpackages.com/badges/dnkfk-yii2-kafka/health.svg)](https://phpackages.com/packages/dnkfk-yii2-kafka)
```

###  Alternatives

[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
