The gemstone.discovery module

Discovery strategies

class gemstone.discovery.BaseDiscoveryStrategy[source]

Base class for service discovery strategies.

locate(name)[source]

Attempts to locate a microservice with the given name. If no such service exists, must return None

Parameters:name – The name of the microservice to be located
Returns:a list of str with the URLs where a microservice with the given name can be found.
ping(name, location, **kwargs)[source]

Pings the service registry as defined by the implemented protocol with the necessary information about the service location.

Parameters:
  • name – The name of the microservice
  • location – The HTTP location of the microservice, where it can be accessed (multiple microservices might have the same location, for example when they are deployed behind a reverse proxy)
Returns:

class gemstone.discovery.HttpDiscoveryStrategy(registry_location)[source]

A discovery strategy that uses the HTTP protocol as transport. Each ping and locate calls translate to HTTP requests.

class gemstone.discovery.RedisDiscoveryStrategy(redis_url, time_to_live=180)[source]

Caches

class gemstone.discovery.ServiceDiscoveryCache(cache_lifetime_in_seconds)[source]

Service discovery cache that keeps entries in memory for a constant period of time.

Example usage:

class MyMicroService(MicroService):
    # ...
    service_registry_cache = ServiceDiscoveryCache(60)  # keeps entries for one minute
    # ...
Parameters:cache_lifetime_in_seconds – int that specifies the cache entry lifetime
class gemstone.discovery.DummyCache[source]

Dummy remote service cache. Always returns None which triggers a service registry query.

Example usage:

class MyMicroService(MicroService):
    # ...
    service_registry_cache = DummyCache()
    # ...