Skip to content

Service

service management framework allowing for service discovery and transparent remoting including multiple possible transport protocols.

AbstractComponent()

Bases: Component, ABC

abstract base class for components

BaseDescriptor(type, decorator)

Bases: Generic[T]

the base class for the meta data of both services and components.

Channel()

Bases: InvocationHandler, ABC

A channel is a dynamic proxy invocation handler and transparently takes care of remoting.

FirstURLSelector

Bases: URLSelector

a url selector always retrieving the first URL given a list of possible URLS

RoundRobinURLSelector()

Bases: URLSelector

a url selector that picks urls sequentially given a list of possible URLS

URLSelector

a url selector retrieves a URL for the next remoting call.

get(urls) abstractmethod

return the next URL given a list of possible URLS

Parameters:

Name Type Description Default
urls list[str]

list of possible URLS

required

Returns:

Type Description
str

a URL

select_first_url()

pick the first URL

select_round_robin()

enable round robin

ChannelAddress(channel, uri) dataclass

A channel address is a combination of:

  • channel: the channel name
  • uri: uri of the appropriate endpoint

ChannelInstances(component, channel, urls=[]) dataclass

a resolved channel address containing:

  • component: the component name
  • channel: the channel name
  • urls: list of URLs

ChannelManager()

Internal factory for channels.

Component

Bases: Service

This is the base class for components.

get_addresses(port) abstractmethod

returns a list of channel addresses that expose this component's services.

Parameters:

Name Type Description Default
port int

the port of a server hosting this component

required

Returns:

Type Description
list[ChannelAddress]

list of channel addresses

get_health() abstractmethod async

return the component health

Returns: the component health

get_status() abstractmethod

return the component status callback

Returns: the component status

shutdown() abstractmethod

shutdown callback

startup() abstractmethod

startup callback

ComponentDescriptor(component_type, service_types)

Bases: BaseDescriptor[T]

meta data for components

ComponentRegistry

A component registry keeps track of components including their health

deregister(descriptor) abstractmethod

deregister a component from the registry Args: descriptor: the component descriptor

get_addresses(descriptor) abstractmethod

return a list of addresses that can be used to call services belonging to this component

Parameters:

Name Type Description Default
descriptor ComponentDescriptor

the component descriptor

required

Returns:

Type Description
list[ChannelInstances]

list of channel instances

register(descriptor, addresses) abstractmethod

register a component to the registry Args: descriptor: the descriptor addresses: list of addresses

watch(channel) abstractmethod

remember the passed channel and keep it informed about address changes Args: channel: a channel

ComponentStatus

Bases: Enum

A component is in one of the following statuses:

  • VIRGIN: just constructed
  • RUNNING: registered and up and running
  • STOPPED: after shutdown

LocalServiceException

Bases: ServiceException

base class for service exceptions occurring locally

RemoteServiceException

Bases: ServiceException

base class for service exceptions occurring on the server side

Server()

Bases: ABC

A server is a central entity that boots a main module and initializes the ServiceManager. It also is the place where http servers get initialized.

get_local_ip() classmethod

return the local ip address

Returns: the local ip address

Service

This is something like a 'tagging interface' for services.

ServiceCommunicationException

Bases: ServiceException

base class for service exceptions thrown by remoting errors

ServiceDescriptor(component_descriptor, service_type)

Bases: BaseDescriptor[T]

meta data for services

ServiceException

Bases: Exception

base class for service exceptions

ServiceInstanceProvider(clazz)

Bases: InstanceProvider

A ServiceInstanceProvider is able to create instances of services.

ServiceManager(component_registry, channel_manager)

Central class that manages services and components and is able to return proxies.

get_service(service_type, preferred_channel='')

return a service proxy given a service type and preferred channel name

Parameters:

Name Type Description Default
service_type Type[T]

the service type

required
preferred_channel

the preferred channel name

''

Returns:

Type Description
T

the proxy

channel(name)

this decorator is used to mark channel implementations.

Parameters:

Name Type Description Default
name str

the channel name

required

component(name='', description='', services=[])

decorates component interfaces

Parameters:

Name Type Description Default
name

the component name. If empty the class name converted to snake-case is used

''
description

optional description

''
services list[Type]

the list of hosted services

[]

health(endpoint='')

specifies the health endpoint that will return the component health

Parameters:

Name Type Description Default
endpoint

the health endpoint

''

implementation()

decorates service or component implementations.

service(name='', description='')

decorates service interfaces

Parameters:

Name Type Description Default
name

the service name. If empty the class name converted to snake case is used

''
description

optional description

''