The LNS protocol specifies that the first request an LBS makes is to the
/router-info discovery endpoint. The LNS from the starter kit implements the
/router-info endpoint and redirects any requests to that endpoint to the
/router-data endpoint on the same LNS.
In addition to the discovery endpoint on the LNS itself, we also support a standalone discovery service, which you can use to dynamically distribute LBS connections to different LNS, ensuring failover of LBS to another LNS in case the current LNS is experiencing downtime. The discovery service is a .NET application, and its implementation is part of the
The discovery service relies on configuration from IoT Hub module twins to associate each LBS with a set of LNS to which it may connect to. For this the configuration needs to take into account possible network boundaries - by defining these networks you can control which LBS should connect to which LNS. For this you need to configure your LBS twin in IoT Hub as follows:
The network ID may only consist of alphanumeric characters. After you configured the LBS, you need to also configure your LNS with the same network. The LNS twin furthermore needs to contain the IP/DNS of the host, hence the twin of the LNS module should look like:
We will only query the LNS module twins for LNS within the same network. If you configure the network/host address on the Edge device twin, it will not be detected.
Keep in mind that the
hostAddress value must include the scheme and the host name. In case you omit the port, the defaults of the protocol will be used.
The discovery endpoint distributes LBS to LNS using a round-robin distribution mechanism. It will always try the same LNS per LBS first. Hence, it can be used for an active/passive scenario, but not to distribute load more evenly across different LNS.
The configuration values of the network name of a station, respectively of the set of LNS in a given network, are cached by the discovery endpoint for 6 hours. If you updated the configuration and want it to take effect sooner, make sure to restart the discovery service to ensure that the cache is refreshed.
You can choose to deploy the discovery service either on-prem or in the cloud. For both deployment strategies, you can configure the following behavior:
You can configure the following behavior of the LNS discovery service.
|Configures the default log level. For more fine-grained configuration of the console log level, refer to Logging in .NET Core and ASP.NET Core
|Sends telemetry data to Application Insights
|Configures the Application Insights log levels
|Configures on which URLs the service is listening. Multiple URLs should be separated by a
|Host name of the Iot Hub. Only used if you connect to IoT Hub using managed identities.
|Connection string to the Iot Hub. In case of App Service deployment, use managed identities instead.
|Configures the certificates that should be used by the discovery endpoint as described in the Minimal APIs overview. Instead of using the
appsettings.json, you can use environment variables of the same structure, where a double underscore replaces a level of hierarchy.
Deployment in Azure
We recommend that you use an Azure App Service to run the discovery service in the cloud. You can follow the App Service Quickstart for instructions how to deploy an ASP.NET Core app in an Azure App Service. When using an App Service, make sure that you:
- Enable the system assigned managed identity
- Assign a role to the system assigned identity which allows it to execute the
Microsoft.Devices/IotHubs/twins/readdata action for reading the IoT Hub twins. Built-in
IoT Hub Twin Contributorrole allows that.
- Specify the Iot Hub host name as described in the configuration section.
When deploying the discovery service on-premises, please read how to Host ASP.NET Core on Windows with IIS (or any other hosting strategy you may want to use).
- The discovery endpoint exposes metrics in Prometheus format.
- You must specify the IoT Hub connection string as described in the configuration section, since you cannot use managed identities with an on-premises deployment.