Integration with Synapse’s file_output service discovery method.


Production Baseplate services have Synapse hooked up to a local HAProxy instance which will automatically route connections to services for you if you connect to the correct address/port on localhost. That is the preferred method of connecting to services.

The contents of this module are useful for inspecting the service inventory directly for cases where a blind TCP connection is insufficient (e.g. to give service addresses to a client, or for topology-aware clients like Cassandra).

A basic example of usage:

inventory = ServiceInventory("/var/lib/synapse/example.json")
backend = inventory.get_backend()
class baseplate.lib.service_discovery.ServiceInventory(filename)[source]

The inventory enumerates available backends for a single service.

Parameters:filename (str) – The absolute path to the Synapse-generated inventory file in JSON format.

Return a list of all available backends in the inventory.

If the inventory file becomes unavailable, the previously seen inventory is returned.

Return type:Sequence[Backend]

Return a randomly chosen backend from the available backends.

If weights are specified in the inventory, they will be respected when making the random selection.

Raises:NoBackendsAvailableError if the inventory has no available endpoints.
Return type:Backend
class baseplate.lib.service_discovery.Backend[source]

A description of a service backend.

This is a tuple of several values:

A unique integer ID identifying the backend.
The name of the backend.
An EndpointConfiguration object describing the network address of the backend.
An integer weight indicating how much to prefer this backend when choosing whom to connect to.


exception baseplate.lib.service_discovery.NoBackendsAvailableError[source]

Raised when no backends are available for this service.