simpod/kafka-bundle
Composer 安装命令:
composer require simpod/kafka-bundle
包简介
Kafka Symfony bundle.
README 文档
README
Installation
Add as Composer dependency:
composer require simpod/kafka-bundle
Then add KafkaBundle to Symfony's bundles.php:
use SimPod\KafkaBundle\SimPodKafkaBundle; return [ ... new SimPodKafkaBundle() ... ];
Usage
This package simply makes it easier to integrate https://github.com/arnaud-lb/php-rdkafka with Symfony. For more details how to work with Kafka in PHP, refer to its documentation.
Available console commands:
bin/console debug:kafka:consumersto list all available consumer groupsbin/console kafka:consumer:run <consumer name>to run consumer instance
Config:
You can create eg. kafka.yaml file in your config directory with following content:
kafka: authentication: '%env(KAFKA_AUTHENTICATION)%' bootstrap_servers: '%env(KAFKA_BOOTSTRAP_SERVERS)%' client: id: 'your-application-name'
authenticationreads env varKAFKA_AUTHENTICATIOnthat contains authentication uri (sasl-plain://user:password, or it might be just empty indicating no authentication).bootstrap_serversreads env varKAFKA_BOOTSTRAP_SERVERSthat contains comma-separated list of bootstrap servers (broker-1.kafka:9092,broker-2.kafka:9092).
If bootstrap_servers isn't set, it defaults to 127.0.0.1:9092
Services
Following services are registered in container and can be DI injected.
Configuration
class: \SimPod\KafkaBundle\Kafka\Configuration
Configuration service allows easy access to all the configuration properties.
$config->set(ConsumerConfig::CLIENT_ID_CONFIG, $this->configuration->getIdWithHostname());
Consuming
There's interface NamedConsumer available. When your consumer implements it, this bundle autoregisters it.
This is example of simple consumer, it can be then run via bin/console kafka:consumer:run consumer1
<?php declare(strict_types=1); namespace Your\AppNamespace; use SimPod\Kafka\Clients\Consumer\ConsumerConfig; use SimPod\Kafka\Clients\Consumer\KafkaConsumer; use SimPod\KafkaBundle\Kafka\Configuration; use SimPod\KafkaBundle\Kafka\Clients\Consumer\NamedConsumer; final class ExampleKafkaConsumer implements NamedConsumer { private Configuration $configuration; public function __construct(Configuration $configuration) { $this->configuration = $configuration; } public function run(): void { $kafkaConsumer = new KafkaConsumer($this->getConfig()); $kafkaConsumer->subscribe(['topic1']); while (true) { ... } } public function getName(): string { return 'consumer1'; } private function getConfig(): ConsumerConfig { $config = new ConsumerConfig(); $config->set(ConsumerConfig::BOOTSTRAP_SERVERS_CONFIG, $this->configuration->getBootstrapServers()); $config->set(ConsumerConfig::ENABLE_AUTO_COMMIT_CONFIG, false); $config->set(ConsumerConfig::CLIENT_ID_CONFIG, $this->configuration->getClientIdWithHostname()); $config->set(ConsumerConfig::AUTO_OFFSET_RESET_CONFIG, 'earliest'); $config->set(ConsumerConfig::GROUP_ID_CONFIG, 'consumer_group'); return $config; } }
Development
There is kwn/php-rdkafka-stubs listed as a dev dependency so it properly integrates php-rdkafka extension with IDE.
simpod/kafka-bundle 适用场景与选型建议
simpod/kafka-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 136.06k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2018 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 simpod/kafka-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simpod/kafka-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 136.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-30