PHPackages                             easyswoole/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. [Framework](/categories/framework)
4. /
5. easyswoole/kafka

ActiveLibrary[Framework](/categories/framework)

easyswoole/kafka
================

An efficient swoole framework

1.0.6(5y ago)4211.1k↑100%17[6 issues](https://github.com/easy-swoole/kafka/issues)[1 PRs](https://github.com/easy-swoole/kafka/pulls)Apache-2.0PHPPHP &gt;=7.1.0

Since Oct 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/easy-swoole/kafka)[ Packagist](https://packagist.org/packages/easyswoole/kafka)[ Docs](https://www.easyswoole.com/)[ RSS](/packages/easyswoole-kafka/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (9)Used By (0)

kafka
=====

[](#kafka)

本项目代码参考自

安装
==

[](#安装)

```
composer require easyswoole/kafka
```

### 注册kafka服务

[](#注册kafka服务)

```
namespace EasySwoole\EasySwoole;

use App\Producer\Process as ProducerProcess;
use App\Consumer\Process as ConsumerProcess;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;

class EasySwooleEvent implements Event
{

    public static function initialize()
    {
        // TODO: Implement initialize() method.
        date_default_timezone_set('Asia/Shanghai');
    }

    public static function mainServerCreate(EventRegister $register)
    {
        // TODO: Implement mainServerCreate() method.
        // 生产者
        ServerManager::getInstance()->getSwooleServer()->addProcess((new ProducerProcess())->getProcess());
        // 消费者
        ServerManager::getInstance()->getSwooleServer()->addProcess((new ConsumerProcess())->getProcess());
    }

    ......

}
```

### 生产者

[](#生产者)

```
namespace App\Producer;

use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\Kafka\Config\ProducerConfig;
use EasySwoole\Kafka\Kafka;

class Process extends AbstractProcess
{
    protected function run($arg)
    {
        go(function () {
            $config = new ProducerConfig();
            $config->setMetadataBrokerList('127.0.0.1:9092,127.0.0.1:9093');
            $config->setBrokerVersion('0.9.0');
            $config->setRequiredAck(1);

            $kafka = new kafka($config);
            $result = $kafka->producer()->send([
                [
                    'topic' => 'test',
                    'value' => 'message--',
                    'key'   => 'key--',
                ],
            ]);

            var_dump($result);
            var_dump('ok');
        });
    }
}
```

### 消费者

[](#消费者)

```
namespace App\Consumer;

use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\Kafka\Config\ConsumerConfig;
use EasySwoole\Kafka\Kafka;

class Process extends AbstractProcess
{
    protected function run($arg)
    {
        go(function () {
            $config = new ConsumerConfig();
            $config->setRefreshIntervalMs(1000);
            $config->setMetadataBrokerList('127.0.0.1:9092,127.0.0.1:9093');
            $config->setBrokerVersion('0.9.0');
            $config->setGroupId('test');

            $config->setTopics(['test']);
            $config->setOffsetReset('earliest');

            $kafka = new Kafka($config);
            // 设置消费回调
            $func = function ($topic, $partition, $message) {
                var_dump($topic);
                var_dump($partition);
                var_dump($message);
            };
            $kafka->consumer()->subscribe($func);
        });
    }
}
```

### docker-compose.yml

[](#docker-composeyml)

```
启动
    docker-compose -f docker-compose.yml up -d
生成更多节点
    docker-compose scale kafka=3
创建topic
    docker exec kafka_kafka_1 kafka-topics.sh  --create --topic test --partitions 3 --zookeeper zookeeper:2181 --replication-factor 3
查看topic
    docker exec kafka_kafka_1 kafka-topics.sh --list --zookeeper zookeeper:2181
生产
    docker exec -it kafka_kafka_1 kafka-console-producer.sh --topic test --broker-list kafka_kafka_1:9092,kafka_kafka_2:9092,kafka_kafka_2:9092
消费
    docker exec -it kafka_kafka_1 kafka-console-consumer.sh --topic test --bootstrap-server kafka_kafka_1:9092,kafka_kafka_2:9092,kafka_kafka_2:9092

```

### Any Question

[](#any-question)

kafka使用问题及bug，欢迎到Easyswoole的kaka群中提问或反馈 QQ群号：827432930

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80.6% 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

Every ~99 days

Recently: every ~164 days

Total

8

Last Release

1689d ago

Major Versions

1.0.6 → 2.x-dev2021-09-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/45c234d5f129ea570e630425636299127647534f0c2cbb073555e2c45d403d6f?d=identicon)[kiss291323003](/maintainers/kiss291323003)

---

Top Contributors

[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (29 commits)")[![evalor](https://avatars.githubusercontent.com/u/26944445?v=4)](https://github.com/evalor "evalor (2 commits)")[![huizhang001](https://avatars.githubusercontent.com/u/26496638?v=4)](https://github.com/huizhang001 "huizhang001 (2 commits)")[![leocavalcante](https://avatars.githubusercontent.com/u/183722?v=4)](https://github.com/leocavalcante "leocavalcante (1 commits)")[![NicholasChan1025](https://avatars.githubusercontent.com/u/29789197?v=4)](https://github.com/NicholasChan1025 "NicholasChan1025 (1 commits)")[![XueSiLf](https://avatars.githubusercontent.com/u/31389659?v=4)](https://github.com/XueSiLf "XueSiLf (1 commits)")

---

Tags

asyncframeworkswooleeasyswoole

### Embed Badge

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

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

###  Alternatives

[easyswoole/easyswoole

An efficient swoole framework

4.8k186.9k50](/packages/easyswoole-easyswoole)[easyswoole/rpc

An efficient swoole framework

7731.6k2](/packages/easyswoole-rpc)[easyswoole/orm

php stander lib

3088.7k17](/packages/easyswoole-orm)[easyswoole/fast-cache

An efficient swoole framework

1030.3k2](/packages/easyswoole-fast-cache)[easyswoole/actor

easyswoole component

1410.3k](/packages/easyswoole-actor)[easyswoole/compiler

easyswoole component

691.1k](/packages/easyswoole-compiler)

PHPackages © 2026

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