PHPackages                             glsv/yii2kafka - 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. glsv/yii2kafka

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

glsv/yii2kafka
==============

Integration of third party clients for kafka for the Yii framework

v0.1.0(5y ago)25151[1 PRs](https://github.com/glsv/yii2kafka/pulls)BSD-3-ClausePHPPHP &gt;=7.1.0

Since Apr 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/glsv/yii2kafka)[ Packagist](https://packagist.org/packages/glsv/yii2kafka)[ RSS](/packages/glsv-yii2kafka/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (2)Used By (0)

Client integration for Kafka in Yii2
====================================

[](#client-integration-for-kafka-in-yii2)

Install
-------

[](#install)

`php composer require glsv/yii2kafka:dev-master`

Supported php-clients
---------------------

[](#supported-php-clients)

- [longyan/phpkafka](https://github.com/longyan/phpkafka)
- [weiboad/kafka-php](https://github.com/weiboad/kafka-php)

Sequence of steps
-----------------

[](#sequence-of-steps)

1. Install `glsv/yii2kafka`
2. Select and install some php-client ([longyan/phpkafka](https://github.com/longyan/phpkafka) or [weiboad/kafka-php](https://github.com/weiboad/kafka-php))
3. Configure extension and client

Configure glsv/yii2kafka
------------------------

[](#configure-glsvyii2kafka)

```
components = [
    'class' => \yii2Kafka\YiiKafkaComponent::class,
    'brokers' => ['kafka:9092'],
    'defaultLogPath' => '@runtime/logs/kafka.log',
    'debugMode' => true,
    'adapter => [
       // configure adapter for php-client...
    ]
]

```

Integration php-client longyan/phpkafka
---------------------------------------

[](#integration-php-client-longyanphpkafka)

`php composer require longlang/phpkafka`

#### Config yii2

[](#config-yii2)

```
components = [
    'class' => \yii2Kafka\YiiKafkaComponent::class,
    'brokers' => ['kafka:9092']
     /**
     * https://github.com/longyan/phpkafka
     */
    'adapter' => [
        'class' => \yii2Kafka\adapters\longlang\LonglangAdapter::class,
        'params' => [
            ////////
            // Use the params for the client at the links:
            // producer: https://github.com/longyan/phpkafka/blob/master/doc/producer.en.md
            // consumer: https://github.com/longyan/phpkafka/blob/master/doc/consumer.en.md
            ////////
            'producer' => [
                'autoCreateTopic' => false,
                'acks' => 1,
            ],
            'consumer' => [
                'topic' => ['test-topic'],
                'groupId' => 'consumer-group',
                'clientId' => 'client-consumer',
            ]
        ],
    ],
]

```

Integration php-client nmred/kafka-php
--------------------------------------

[](#integration-php-client-nmredkafka-php)

`php composer require nmred/kafka-php`

#### Config yii2 with nmred/kafka-php

[](#config-yii2-with-nmredkafka-php)

```
components = [
    'class' => \yii2Kafka\YiiKafkaComponent::class,
    'brokers' => ['kafka:9092']
    /**
     * https://github.com/weiboad/kafka-php
     */
    'adapter' => [
        'class' => \yii2Kafka\adapters\nmred\NmredAdapter::class,
        'params' => [
            ////////
            // Use the params for the client at the link:
            // https://github.com/weiboad/kafka-php/blob/master/docs/Configure.md
            ////////
            'global' => [],
            'producer' => [
                'isAsyn' => false,
                'requiredAck' => 1,
            ],
            'consumer' => [
                'topics' => ['test-topic'],
                'groupId' => 'consumer-group'
            ]
        ]
    ],
]

```

Produce example
---------------

[](#produce-example)

**Producing single message**

```
/**
 * @var YiiKafkaComponent $kafka
 */
$kafka = \Yii::$app->kafka;

$producer = $kafka->getProducer();
$topicName = "test-topic"
$producer->send($topicName, 'Message: ' . date('d.m H:i:s'), '');

```

**Producing messages in batches**

```
/**
 * @var YiiKafkaComponent $kafka
 */
$kafka = \Yii::$app->kafka;

$producer = $kafka->getProducer();
$topicName = "test-topic"
$messages = [
    new Message($topicName, 'Message 1: ' . date('d.m H:i:s')),
    new Message($topicName, 'Message 2: ' . date('d.m H:i:s')),
];

$producer->sendBatch($messages);

```

Consume example
---------------

[](#consume-example)

**Consuming messages from a topic from settings**

```
/**
 * @var YiiKafkaComponent $kafka
 */
$kafka = \Yii::$app->kafka;

$consumer = $kafka->getConsumer();
$consumer->consume(function ($message) {
    var_dump($message);
});

```

**Consuming messages from a topic from settings**

```
/**
 * @var YiiKafkaComponent $kafka
 */
$kafka = \Yii::$app->kafka;
$topicName = 'another-topic';

$config = new ConsumerConfig($topicName);
$config->setClientId('client_2');
$config->setGroupIp('group_2');

$consumer = $kafka->getAdapterClient()->createConsumer($config);
$consumer->consume(function ($message) {
    var_dump($message);
});

```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

1891d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91df1131c4f59121e535490b3bfb19d1507d8f3c42c127163955a2907c2072e1?d=identicon)[glsv](/maintainers/glsv)

---

Tags

yii2kafkakafka-client

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/glsv-yii2kafka/health.svg)

```
[![Health](https://phpackages.com/badges/glsv-yii2kafka/health.svg)](https://phpackages.com/packages/glsv-yii2kafka)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.0k](/packages/craftcms-cms)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)

PHPackages © 2026

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