Skip to content
This repository was archived by the owner on Jun 3, 2022. It is now read-only.

CascadeEnergy/php-consul-http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-consul-http-client

Allows for Consul Service Lookup over HTTP

This module requests all passing consul services with the desired name, and optional version tag, and returns the URL of a randomly selected copy of the service.

Example:

<?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...
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages