apicrud.ServiceRegistry¶
-
class
apicrud.
ServiceRegistry
(aes_secret=None, redis_conn=None, public_url=None, reload_params=False, ttl=None)¶ Service Registry
Services or the UI discover one another through this service registry. Each microservice instance submits its identity and capabilities to this central registry, implemented as expiring redis keys which are updated at a fixed frequency. Encryption provides modest protection against injection attacks.
- Parameters
aes_secret (str) – an AES secret [default: config.REDIS_AES_SECRET]
public_url (str) – URL to serve [default: config.PUBLIC_URL]
redis_conn (obj) – connection to redis
reload_params (bool) – force param reload, for unit-testing
ttl (int) – how long to cache instance’s registration
-
__init__
(aes_secret=None, redis_conn=None, public_url=None, reload_params=False, ttl=None)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([aes_secret, redis_conn, …])Initialize self.
find
([service_name])Finds one or all services
get
()return service registration for local instance
register
(resource_endpoints[, service_name, …])register an instance serving a list of endpoints
update
()background function to update registration at the defined interval from local memory cache, until the instance terminates.
-
find
(service_name=None)¶ Finds one or all services
- Parameters
service_name (str) – a service, or None for all
- Returns
- dict - instances (list of registered services)
url_map (public url for each top-level resource)
-
get
()¶ return service registration for local instance
- Returns: dict(name, id, info)
Key info is dict(endpoints, ipv4, port, public_url, created)
-
register
(resource_endpoints, service_name=None, instance_id='build-13556024-project-613164-apicrud', tcp_port=None)¶ register an instance serving a list of endpoints
- Parameters
resource_endpoints (list of str) – controller endpoints served
service_name (str) – microservice name
instance_id (str) – unique ID of instance
tcp_port (int) – port number of service
-
static
update
()¶ background function to update registration at the defined interval from local memory cache, until the instance terminates.