indigerd/php-consul-sdk
最新稳定版本:v1.2.2
Composer 安装命令:
composer require indigerd/php-consul-sdk
包简介
PHP Consul SDK.
README 文档
README
Usage
The simple way to use this SDK, is to instantiate the service factory:
$factory = new \indigerd\consul\ServiceFactory(); /* @var \indigerd\consul\services\ServiceKeyValue $kv */ $kv = $factory->get('kv'); $model = new \indigerd\consul\models\KeyValue(); $model->setKey('test-value'); $model->setValue('Some test content'); $kv->setKeyValue($model); $v = $kv->getKeyValue($model->getKey()); /* @var \indigerd\consul\services\ServiceRegistry $registry */ $registry = $factory->get('registry'); $service = new \indigerd\consul\models\Service(); $service->setName('TestMicroService'); $service->setAddress('192.168.44.177'); $service->setPort(80); $registry->register($service); /* @var \indigerd\consul\services\ServiceDiscovery $discovery */ $discovery = $factory->get('discovery'); $address = $discovery->getServiceAddress($service->getName()); class ConsulHeartBeatCommand { const EXIT_CODE_NORMAL = 0; const EXIT_CODE_ERROR = 1; const EXIT_CODE_CONSUL_HEARTBEAT_FAIL = 2; public $defaultAction = 'respond'; public function run($name, $id = '') { $service = new \indigerd\consul\models\Service(); $service->setName($name); if (!empty($id)) { $service->setId($id); } $factory = new \indigerd\consul\ServiceFactory(); $heartBeat = $factory->get('health'); $heartBeat->addHealthCheck(function () { return (4 === 2 + 2); }); try { $health = $heartBeat->run($service); } catch (\Exception $e) { $health = false; } if ($health) { return self::EXIT_CODE_NORMAL; } return self::EXIT_CODE_CONSUL_HEARTBEAT_FAIL; } } $command = new ConsulHeartBeatCommand; $health = $command->run($service->getName());
统计信息
- 总下载量: 3.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-23