Microsoft.Extensions.ServiceDiscovery.Dns
9.0.0
Prefix Reserved
dotnet add package Microsoft.Extensions.ServiceDiscovery.Dns --version 9.0.0
NuGet\Install-Package Microsoft.Extensions.ServiceDiscovery.Dns -Version 9.0.0
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery.Dns" Version="9.0.0" />
paket add Microsoft.Extensions.ServiceDiscovery.Dns --version 9.0.0
#r "nuget: Microsoft.Extensions.ServiceDiscovery.Dns, 9.0.0"
// Install Microsoft.Extensions.ServiceDiscovery.Dns as a Cake Addin #addin nuget:?package=Microsoft.Extensions.ServiceDiscovery.Dns&version=9.0.0 // Install Microsoft.Extensions.ServiceDiscovery.Dns as a Cake Tool #tool nuget:?package=Microsoft.Extensions.ServiceDiscovery.Dns&version=9.0.0
Microsoft.Extensions.ServiceDiscovery.Dns
This library provides support for resolving service endpoints using DNS (Domain Name System). It provides two service endpoint providers:
DNS, which resolves endpoints using DNS
A/AAAA
record queries. This means that it can resolve names to IP addresses, but cannot resolve port numbers endpoints. As such, port numbers are assumed to be the default for the protocol (for example, 80 for HTTP and 433 for HTTPS). The benefit of using the DNS provider is that for cases where these default ports are appropriate, clients can spread their requests across hosts. For more information, see Load-balancing with endpoint selectors.DNS SRV, which resolves service names using DNS SRV record queries. This allows it to resolve both IP addresses and port numbers. This is useful for environments which support DNS SRV queries, such as Kubernetes (when configured accordingly).
Resolving service endpoints with DNS
The DNS service endpoint provider resolves endpoints using DNS A/AAAA
record queries. This means that it can resolve names to IP addresses, but cannot resolve port numbers endpoints. As such, port numbers are assumed to be the default for the protocol (for example, 80 for HTTP and 433 for HTTPS). The benefit of using the DNS service endpoint provider is that for cases where these default ports are appropriate, clients can spread their requests across hosts. For more information, see Load-balancing with endpoint selectors.
To configure the DNS service endpoint provider in your application, add the DNS service endpoint provider to your host builder's service collection using the AddDnsServiceEndpointProvider
method. service discovery as follows:
builder.Services.AddServiceDiscoveryCore();
builder.Services.AddDnsServiceEndpointProvider();
Resolving service endpoints in Kubernetes with DNS SRV
When deploying to Kubernetes, the DNS SRV service endpoint provider can be used to resolve endpoints. For example, the following resource definition will result in a DNS SRV record being created for an endpoint named "default" and an endpoint named "dashboard", both on the service named "basket".
apiVersion: v1
kind: Service
metadata:
name: basket
spec:
selector:
name: basket-service
clusterIP: None
ports:
- name: default
port: 8080
- name: dashboard
port: 8888
To configure a service to resolve the "dashboard" endpoint on the "basket" service, add the DNS SRV service endpoint provider to the host builder as follows:
builder.Services.AddServiceDiscoveryCore();
builder.Services.AddDnsSrvServiceEndpointProvider();
The special port name "default" is used to specify the default endpoint, resolved using the URI http://basket
.
As in the previous example, add service discovery to an HttpClient
for the basket service:
builder.Services.AddHttpClient<BasketServiceClient>(
static client => client.BaseAddress = new("http://basket"));
Similarly, the "dashboard" endpoint can be targeted as follows:
builder.Services.AddHttpClient<BasketServiceDashboardClient>(
static client => client.BaseAddress = new("http://_dashboard.basket"));
Feedback & contributing
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- DnsClient (>= 1.8.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Features (>= 8.0.11)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- Microsoft.Extensions.ServiceDiscovery (>= 9.0.0)
- Microsoft.Extensions.ServiceDiscovery.Abstractions (>= 9.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Microsoft.Extensions.ServiceDiscovery.Dns:
Package | Downloads |
---|---|
ServiceDiscovery.NET
Extensible service discovery for .NET |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Microsoft.Extensions.ServiceDiscovery.Dns:
Repository | Stars |
---|---|
abpframework/eShopOnAbp
Reference microservice solution built with the ABP Framework and .NET, runs on Kubernetes with Helm configuration, includes API Gateways, Angular and ASP.NET Core MVC applications, PostgreSQL and MongoDB databases
|
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 802 | 11/12/2024 |
9.0.0-rc.1.24511.1 | 333 | 10/15/2024 |
8.2.2 | 2,306 | 10/24/2024 |
8.2.1 | 4,049 | 9/26/2024 |
8.2.0 | 3,686 | 8/29/2024 |
8.1.0 | 2,734 | 7/23/2024 |
8.0.2 | 1,390 | 6/28/2024 |
8.0.1 | 7,954 | 5/21/2024 |
8.0.0 | 353 | 5/21/2024 |
8.0.0-preview.7.24251.11 | 181 | 5/7/2024 |
8.0.0-preview.6.24214.1 | 456 | 4/23/2024 |
8.0.0-preview.5.24201.12 | 1,687 | 4/9/2024 |
8.0.0-preview.4.24156.9 | 512 | 3/12/2024 |
8.0.0-preview.3.24105.21 | 2,354 | 2/13/2024 |
8.0.0-preview.2.23619.3 | 1,428 | 12/20/2023 |
8.0.0-preview.1.23557.2 | 1,649 | 11/14/2023 |