kpacha/suricate-php-sdk
Composer 安装命令:
composer require kpacha/suricate-php-sdk
包简介
sdk for the suricate service.
关键字:
README 文档
README
A suricate sdk for php
#Requirements
- git
- suricate server (or any other curator-x-discovery-service)
- php 5.3.3+
- curl extension
#Installation
##Standalone
###Git installation
Clone the repo
$ git clone https://github.com/kpacha/suricate-php-sdk.git
Install the php dependencies
$ cd suricate-php-sdk
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
###Composer installation
Create a project with composer
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar create-project kpacha/suricate-php-sdk [directory]
Remeber to set the [directory] parameter or composer will create the project in your current path.
##As a library
Include the kpacha/suricate-php-sdk package in your compose.json with all the dependencies of your project
"require":{
"kpacha/suricate-php-sdk": "~1.0"
}
#Usage
The suricate sdk comes with a simple client and several console commands bundled in a simple app.
###Suricate client
The Kpacha\Suricate\Suricate constructor requires a rest client. The client must implement the Guzzle\Http\ClientInterface interface.
use Guzzle\Http\Client;
use Kpacha\Suricate\Suricate;
$suricateClient = new Suricate(new Client($suricateServerUrl));
Also, there is a builder to help you
use Kpacha\Suricate\SuricateBuilder;
$suricateClient = SuricateBuilder::build(suricateServerUrl);
And now the $suricateClient object is ready to work. Here you have some examples
try{
$success = $suricateClient->putService($serviceName, $nodeId, $node);
$serviceNames = $suricateClient->getAllNames();
$nodes = $suricateClient->getAll($serviceName);
$node = $suricateClient->get($serviceName, $nodeId);
$success = $suricateClient->removeService($serviceName, $nodeId);
} catch (\Kpacha\Suricate\SuricateException $e) {
// do something cleaver
}
Check the test for more details.
###Suricate console app
Run the suricate script to trigger any console command. You can use them as a:
- simple manager limited to some basic interactions with your suricate service
- simple agent to send some heartbeats to suricate (it should be monitored by some external tool, restarting it periodically). This way, suricate will be aware of the status of your node.
- base for your more complex consumption patterns. Usually, you will also need to fetch all the available nodes registered under the services you are interested in.
Check out the list built-in command and get a list of all the available commands.
$ bin/suricate list
----------------------------------------------------------------------------
.oooooo..o o8o .
d8P' `Y8 `"' .o8
Y88bo. oooo oooo oooo d8b oooo .ooooo. .oooo. .o888oo .ooooo.
`"Y8888o. `888 `888 `888""8P `888 d88' `"Y8 `P )88b 888 d88' `88b
`"Y88b 888 888 888 888 888 .oP"888 888 888ooo888
oo .d8P 888 888 888 888 888 .o8 d8( 888 888 . 888 .o
8""88888P' `V88V"V8P' d888b o888o `Y8bod8P' `Y888""8o "888" `Y8bod8P'
----------------------------------------------------------------------------
Suricate version 0.0.1-Beta
Usage:
[options] command [arguments]
Options:
--help -h Display this help message.
--quiet -q Do not output any message.
--verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version -V Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction -n Do not ask any interactive question.
Available commands:
help Displays help for a command
list Lists commands
suricate
suricate:all Get a list of all the registered nodes by a given service (getAll)
suricate:get Get a node by a given service and id (get)
suricate:heartbeat Put a node by in a service cluster and update it periodically
suricate:names Get a list of all the registered service names (getAllNames)
suricate:put Put a node in a service cluster (putService)
suricate:remove Remove a node by a given service and id (removeService)
Remember, you can also get more details about any command just adding the --help option.
$ bin/suricate suricate:heartbeat --help
Usage:
suricate:heartbeat [-s|--service="..."] [-i|--id="..."] [--node="..."] [-t|--total="..."] [-w|--wait="..."] suricate-server
Arguments:
suricate-server the suricate server url
Options:
--service (-s) name of the servie
--id (-i) id of the node
--node the node in json format
--total (-t) the total heartbeats to send
--wait (-w) the sleep time between consecutive heartbeats in secs
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
Suricate only accepts payloads as String, so you should model your data with that in mind and, maybe, instead of seeing it as a limitation and send just plain texts, you would add some serializated info. Just remember, ZooKeeper is not a database, so use it with caution!
kpacha/suricate-php-sdk 适用场景与选型建议
kpacha/suricate-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「service discovery」 「zookeeper」 「suricate」 「curator」 「curator-x-discovery」 「curator-x-discovery-server」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kpacha/suricate-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kpacha/suricate-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kpacha/suricate-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package to integrate the Httplug generic HTTP client into Laravel
Lightweight mock implementations of PSR-18, PSR-17 and PSR-7 tailored to simplify unit testing.
A fast and intuitive dependency injection container.
Registry service.
A PHP client for Spring Cloud Eureka discovery server.
short description
统计信息
- 总下载量: 74
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2014-03-16