While consuming a lot of different API, the problem to solve is to simplify the registration of services and its discoverability.
So the first approach is to have a static discovery, like we have in the previous simple, but it means have a registry of services in a configuration. The :term:`service registry` may be commited in a tool like puppet, but in case there is a lots of services, this does not scale, periodic run of a puppet agent must run to discover new services.
To avoid the static inventory of service, tools may be used to handle the :term:`service registry`, and build a :term:`client-side service discovery` or a server-side discovery to have a dynamic approach.
.. literalinclude:: sd_static_async.py
.. literalinclude:: sd_static_sync.py
In that case we have a registry of public service.
Note
Because those service does not share the same Authentication mechanism, this example is not really usefull. By the way, writin a custom :ref:`Authentication Middleware` can handle it.
ConsulDiscovery is consuming the Consul API to fetch host that are registered client side, this is a :term:`client-side service discovery`.
.. literalinclude:: sd_consul_async.py
.. literalinclude:: sd_consul_sync.py
Warning
Using consul in client require some discipline in naming convention, endoint must match pattern to build the rest endpoint. So every endpoint must follow the same pattern here.
Note
Take a look at the example!
https://github.com/mardiros/blacksmith/tree/master/examples/consul_sd
RouterDiscovery is calling every service behind a service gateway, a proxy, that is connected to the :term:`service registry` to update is configuration.
.. literalinclude:: sd_router_async.py
.. literalinclude:: sd_router_sync.py
Warning
Every endpoint must follow the same pattern here, it works well if the router configuration is based on a :term:`service registry`, but if the configuration of the router is maded by humans, inconcistency may exists, and the Static Discovery should be used instead.
Note
Take a look at the example!
https://github.com/mardiros/blacksmith/tree/master/examples/consul_template_sd