apicrud.ServiceRegistry

class apicrud.ServiceRegistry(ttl=None, redis_conn=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
  • ttl (int) – how long to cache instance’s registration

  • redis_conn (obj) – connection to redis

__init__(ttl=None, redis_conn=None)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([ttl, redis_conn])

Initialize self.

find([service_name])

Finds one or all services

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)

register(resource_endpoints, service_name=None, instance_id='build-12732349-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.