yaangvu/php-eureka-client
最新稳定版本:v1.1.22
Composer 安装命令:
composer require yaangvu/php-eureka-client
包简介
PHP client for the Netflix Eureka server.
README 文档
README
PHP Eureka Client
PHP client for the Netflix Eureka server. Supports all Eureka REST operations.
Installation
Run
composer require yaangvu/php-eureka-client
or add dependency to your composer.json file
"require": {
...
"yaangvu/php-eureka-client": "^1.0"
}
Usage example
1. Use needed packages
2. Create Eureka app instance
// We will use app name and instance id for making requests below. $appName = 'new_app'; $instanceId = 'test_instance_id'; // Create app instance metadata. $metadata = new Metadata(); $metadata->set('test_key', 'test_value'); // Create data center metadata (required for Amazon only). $dataCenterMetadata = new Metadata(); $dataCenterMetadata->set('data_center_test_key', 'data_center_test_value'); // Create data center info (Amazon example). $dataCenterInfo = new DataCenterInfo(); $dataCenterInfo ->setName('Amazon') ->setClass('com.netflix.appinfo.AmazonInfo') ->setMetadata($dataCenterMetadata); // Create data center info (Own Data Center). $dataCenterInfo = new DataCenterInfo(); $dataCenterInfo ->setName('MyOwn') ->setClass('com.netflix.appinfo.MyDataCenterInfo'); // Create Eureka app instance. $instance = new Instance(); $instance ->setInstanceId($instanceId) ->setHostName('test_host_name') ->setApp($appName) ->setIpAddr('127.0.0.1') ->setPort(80) ->setSecurePort(433) ->setHomePageUrl('http://localhost') ->setStatusPageUrl('http://localhost/status') ->setHealthCheckUrl('http://localhost/health-check') ->setSecureHealthCheckUrl('https://localhost/health-check') ->setVipAddress('test_vip_address') ->setSecureVipAddress('test_secure_vip_address') ->setMetadata($metadata) ->setDataCenterInfo($dataCenterInfo);
3. Create Eureka client
// Eureka client usage example. // Create guzzle client. $guzzle = new Client(); // Create eureka v2 client. $eurekaClient = new EurekaClient('localhost', 8080, $guzzle); // Create eureka v1 client. $eurekaClient = new EurekaClient('localhost', 8080, $guzzle, 'eureka');
4. Make requests
try { // Register new application instance. $response = $eurekaClient->register($appName, $instance); // Query for all instances. $allApps = $eurekaClient->getAllApps(); // Query for all application instances. $app = $eurekaClient->getApp($appName); // Query for a specific application instance. $appInstance = $eurekaClient->getAppInstance($appName, $instanceId); // Query for a specific instance. $instance = $eurekaClient->getInstance($instanceId); // Send application instance heartbeat. $response = $eurekaClient->heartBeat($appName, $instanceId); // Take instance out of service. $response = $eurekaClient->takeInstanceOut($appName, $instanceId); // Put instance back into service. $response = $eurekaClient->putInstanceBack($appName, $instanceId); // Update metadata. $response = $eurekaClient->updateAppInstanceMetadata($appName, $instanceId, [ 'new_key' => 'new_value', ]); // Query for all instances under a particular vip address/ $instances = $eurekaClient->getInstancesByVipAddress('test_vip_address'); // Query for all instances under a particular secure vip address. $instances = $eurekaClient->getInstancesBySecureVipAddress('test_secure_vip_address'); // De-register application instance. $response = $eurekaClient->deRegister($appName, $instanceId); } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; }
Fork from
统计信息
- 总下载量: 6.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-12