superbalist/php-pubsub-kafka
最新稳定版本:2.0.0
Composer 安装命令:
composer require superbalist/php-pubsub-kafka
包简介
A Kafka adapter for the php-pubsub package
README 文档
README
A Kafka adapter for the php-pubsub package.
Installation
-
Install librdkafka c library
$ cd /tmp $ mkdir librdkafka $ cd librdkafka $ git clone https://github.com/edenhill/librdkafka.git . $ ./configure $ make $ make install
-
Install the php-rdkafka PECL extension
$ pecl install rdkafka
-
Add the following to your php.ini file to enable the php-rdkafka extension
extension=rdkafka.so -
composer require superbalist/php-pubsub-kafka
Usage
// create consumer $topicConf = new \RdKafka\TopicConf(); $topicConf->set('auto.offset.reset', 'largest'); $conf = new \RdKafka\Conf(); $conf->set('group.id', 'php-pubsub'); $conf->set('metadata.broker.list', '127.0.0.1'); $conf->set('enable.auto.commit', 'false'); $conf->set('offset.store.method', 'broker'); $conf->set('socket.blocking.max.ms', 50); $conf->setDefaultTopicConf($topicConf); $consumer = new \RdKafka\KafkaConsumer($conf); // create producer $conf = new \RdKafka\Conf(); $conf->set('socket.blocking.max.ms', 50); $conf->set('queue.buffering.max.ms', 20); $producer = new \RdKafka\Producer($conf); $producer->addBrokers('127.0.0.1'); $adapter = new \Superbalist\PubSub\Kafka\KafkaPubSubAdapter($producer, $consumer); // consume messages // note: this is a blocking call $adapter->subscribe('my_channel', function ($message) { var_dump($message); }); // publish messages $adapter->publish('my_channel', 'HELLO WORLD'); $adapter->publish('my_channel', ['hello' => 'world']); $adapter->publish('my_channel', 1); $adapter->publish('my_channel', false); // publish multiple messages $messages = [ ['hello' => 'world'], 'lorem ipsum', ]; $adapter->publishBatch('my_channel', $messages);
Examples
The library comes with examples for the adapter and a Dockerfile for running the example scripts.
Run make up.
You will start at a bash prompt in the /opt/php-pubsub directory.
If you need another shell to publish a message to a blocking consumer, you can run make shell
To run the examples:
$ php examples/KafkaConsumerExample.php $ php examples/KafkaPublishExample.php (in a separate shell)
superbalist/php-pubsub-kafka 适用场景与选型建议
superbalist/php-pubsub-kafka 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.69k 次下载、GitHub Stars 达 30, 最近一次更新时间为 2016 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 superbalist/php-pubsub-kafka 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 superbalist/php-pubsub-kafka 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 66.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 14
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-03