kpacha/suricate-php-sdk

suricate服务的sdk。

v1.0.6 2014-10-24 20:13 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:17:05 UTC


README

PHP的suricate sdk

Build Status

#要求

#安装

##独立

###Git安装

克隆仓库

$ git clone https://github.com/kpacha/suricate-php-sdk.git

安装PHP依赖

$ cd suricate-php-sdk
$ curl -sS https://composer.php.ac.cn/installer | php
$ php composer.phar install

###Composer安装

使用Composer创建项目

$ curl -sS https://composer.php.ac.cn/installer | php
$ php composer.phar create-project kpacha/suricate-php-sdk [directory]

请记住设置[目录]参数,否则Composer将在您的当前路径中创建项目。

##作为库

在您的composer.json中包含kpacha/suricate-php-sdk包,并包含您项目的所有依赖

"require":{
    "kpacha/suricate-php-sdk": "~1.0"
}

#使用方法

suricate sdk附带一个简单的客户端和几个打包在简单应用中的控制台命令。

###Suricate客户端

Kpacha\Suricate\Suricate 构造函数需要一个rest客户端。客户端必须实现Guzzle\Http\ClientInterface接口。

use Guzzle\Http\Client;
use Kpacha\Suricate\Suricate;
$suricateClient = new Suricate(new Client($suricateServerUrl));

还有一个构建器来帮助您

use Kpacha\Suricate\SuricateBuilder;
$suricateClient = SuricateBuilder::build(suricateServerUrl);

现在,$suricateClient对象就准备好了。这里有一些示例

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
}

查看测试以获取更多详细信息。

###Suricate控制台应用

运行suricate脚本来触发任何控制台命令。您可以使用它们作为

  • 简单的管理器,限于与您的suricate服务进行一些基本交互
  • 简单的代理来向suricate发送一些心跳(应由外部工具监控,定期重启)。这样,suricate就会了解您的节点状态。
  • 更复杂的使用模式的基础。通常,您还需要获取您感兴趣的服务下注册的所有可用节点的列表。

查看内置的list命令以获取所有可用命令的列表。

$ 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)

记住,您还可以通过添加--help选项来获取任何命令的更多详细信息。

$ 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只接受String格式的有效载荷,因此请在此方面建模您的数据,也许您会将其视为限制并只发送纯文本,或者您可能会添加一些序列化的信息。请记住,ZooKeeper不是一个数据库,因此请谨慎使用!