Service Discovery¶
For Suite Services, you just need to inject the AppService's interface of the service that you'd like to use and the wiring is done by the Suite Framework.
However, If you'd like to know how it works under the hood, keep reading.
When consuming a service in .Net, you use an HttpClient created through an
IHttpClientFactory. The .AddServiceDiscovery() extension method must be
added.
When doing so, a DelegatingHandler is added to the HttpClient's pipeline
which will assume that the host of the RequestUri is the name of a service. It
will attempt to discover a service with that name and replace the RequestUri's
host with an address for reaching that service. For example:
You can then inject IHttpClientFactory for creating clients.
| C# | |
|---|---|
If the service you're consuming is not an HTTP Service, you need to inject the
IServiceDiscoveryService and use it to resolved the address instead:
| C# | |
|---|---|
GetAddressForServiceAsync will return a single address and take care of the
load balancing process.
Default Service Discovery Provider¶
The ServiceDiscoveryModule supports configuring a provider for performing the
actual discovery from a service registry.
The default implementation uses values from IConfiguration which means that
the actual information for the services may come from different or multiple
sources.
Configuration Example¶
Since the default implementation gets the values from IConfiguration to
resolve services, we may use the appsettings.json file to provide them. This
is a good setup for development purposes.
For example:
This will register two services, identity-service and aims-api-service. Some
things to note:
- No protocol is specified. i.e, no http/s is provided. The
addressesis a list of network addresses, which in the case of the default provider, may support a relative path. However, URLs are not supported. - If the connection will be secured or not (https) will be decided at runtime
by the consumer through the
EnforceSecureChannelsconfig of the Service Discovery Module. It is the consumer's desire to connect securely due to the importance of the data being sent.