cascade-energy / php-consul-http-client
此包已被弃用且不再维护。未建议替代包。
基于HTTP的Consul服务发现客户端
v0.1.0
2015-12-10 21:24 UTC
Requires
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- phpunit/phpunit: ^4.7
This package is not auto-updated.
Last update: 2022-06-11 06:08:11 UTC
README
支持通过HTTP进行Consul服务查找
此模块请求所有具有所需名称(可选版本标签)的通过验证的consul服务,并返回随机选择的服务副本的URL。
示例
<?php
// Passing `null` as the first argument lets the module create it's own http client
$serviceLookup = new CascadeEnergy\ServiceDiscovery\Consul\ConsulHttp(null,"<ip-of-consul-server>:8500");
// `service-version` is optional
$serviceUrl = $serviceLookup->getServiceAddress(<service-name>, <service-version>);
if ($serviceUrl == null) {
//If no healthy instances of the desired service are found, the url returned is `null`
//this can be handled in any convenient manner such as:
throw new Exception('Service not found!');
} else {
//The service was found!
$client = new <insert-your-favorite-http-client-here>();
$request = $client->put("$url/<route>",null,<body>);
// keep interacting with the service, ask for urls of new services, etc...
}