imiphp/imi-zookeeper

imi 框架 ZooKeeper 组件。imi ZooKeeper component.

v2.1.0-beta1 2022-09-02 06:55 UTC

This package is auto-updated.

Last update: 2024-04-10 08:08:58 UTC


README

Latest Version Php Version Swoole Version IMI License

介绍

此项目是 imi 框架的 ZooKeeper 组件。

正在开发中,随时可能修改,请勿用于生产环境!

支持的功能:

  • 配置中心

安装

PHP 扩展

本组件

本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 composer.json 中加入下面的内容:

{
    "require": {
        "imiphp/imi-zookeeper": "~2.1.0"
    }
}

然后执行 composer update 安装。

使用说明

配置

@app.beans

[
    'ConfigCenter' => [
        // 'mode'    => \Imi\ConfigCenter\Enum\Mode::WORKER, // 工作进程模式
        'mode'    => \Imi\ConfigCenter\Enum\Mode::PROCESS, // 进程模式
        'configs' => [
            'zookeeper' => [
                'driver'  => \Imi\ZooKeeper\Config\SwooleZooKeeperConfigDriver::class, // Swoole 驱动
                // 'driver'  => \Imi\ZooKeeper\Config\ZooKeeperConfigDriver::class, // 非 Swoole 驱动
                // 客户端连接配置
                'client'  => [
                    'host'    => env('IMI_ZOOKEEPER_HOST', '127.0.0.1:2181'), // 主机名:端口
                    'timeout' => 10, // 网络请求超时时间,单位:秒
                ],
                // 监听器配置
                'listener' => [
                    'timeout'         => 30000, // 配置监听器长轮询超时时间,单位:毫秒
                    'failedWaitTime'  => 3000, // 失败后等待重试时间,单位:毫秒
                    'savePath'        => Imi::getRuntimePath('config-cache'), // 配置保存路径,默认为空不保存到文件。php-fpm 模式请一定要设置!
                    'fileCacheTime'   => 30, // 文件缓存时间,默认为0时不受缓存影响,此配置只影响 pull 操作。php-fpm 模式请一定要设置为大于0的值!
                    'pollingInterval' => 10000, // 客户端轮询间隔时间,单位:毫秒
                ],
                // 配置项
                'configs' => [
                    'zookeeper' => [
                        'key'   => 'imi-zooKeeper-key1',
                        'type'  => 'json', // 配置内容类型
                    ],
                ],
            ],
        ],
    ],
]

获取配置

\Imi\Config::get('zookeeper'); // 对应 imi-zooKeeper-key1

写入配置

/** @var \Imi\ConfigCenter\ConfigCenter $configCenter */
$configCenter = App::getBean('ConfigCenter');
$name = 'imi-zooKeeper-key1';
$value = json_encode(['imi' => 'niubi']);
$configCenter->getDriver('zookeeper')->push($name, $value);

社群

imi 框架交流群: 17916227 点击加群

微信群:

imi

打赏赞助: https://www.imiphp.com/donate.html

运行环境

版权信息

imi-zookeeper 遵循 MIT 开源协议发布,并提供免费使用。