.NET Aspire Milvus database component
In this article, you learn how to use the .NET Aspire Milvus database component. The Aspire.Milvus.Client
library registers a MilvusClient in the DI container for connecting to a Milvus server.
Prerequisites
- Milvus server and connection string for accessing the server API endpoint.
Get started
To get started with the .NET Aspire Milvus database component, install the Aspire.Milvus.Client NuGet package in the consuming client project.
dotnet add package Aspire.Milvus.Client
For more information, see dotnet add package or Manage package dependencies in .NET applications.
Example usage
In the Program.cs file of your project, call the AddMilvusClient
extension method to register a MilvusClient
for use via the dependency injection container. The method takes a connection name parameter.
builder.AddMilvusClient("milvus");
App host usage
To model the Milvus resource in the app host, install the Aspire.Hosting.Milvus NuGet package in the app host project.
dotnet add package Aspire.Hosting.Milvus
In the Program.cs file of AppHost
, register a Milvus server and consume the connection using the following methods:
var milvus = builder.AddMilvus("milvus");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(milvus);
The WithReference
method configures a connection in the MyService
project named milvus
. In the Program.cs file of MyService
, the Milvus connection can be consumed using:
builder.AddMilvusClient("milvus");
Configuration
The .NET Aspire Milvus Client component provides multiple options to configure the server connection based on the requirements and conventions of your project.
Tip
The default use is root
and the default password is Milvus
. Currently, Milvus doesn't support changing the superuser password at startup. It needs to be manually changed with the client.
Use a connection string
When using a connection string from the ConnectionStrings
configuration section, you can provide the name of the connection string when calling builder.AddMilvusClient()
:
builder.AddMilvusClient("milvus");
And then the connection string will be retrieved from the ConnectionStrings
configuration section:
{
"ConnectionStrings": {
"milvus": "Endpoint=http://localhost:19530/;Key=root:123456!@#$%"
}
}
By default the MilvusClient
uses the gRPC API endpoint.
Use configuration providers
The .NET Aspire Milvus Client component supports Microsoft.Extensions.Configuration. It loads the MilvusSettings
from configuration by using the Aspire:Milvus:Client
key. Consider the following example appsettings.json that configures some of the options:
{
"Aspire": {
"Milvus": {
"Client": {
"Key": "root:123456!@#$%"
}
}
}
}
Use inline delegates
Also you can pass the Action<MilvusSettings> configureSettings
delegate to set up some or all the options inline, for example to set the API key from code:
builder.AddMilvusClient(
"milvus",
settings => settings.Key = "root:12345!@#$%");
Health checks
By default, .NET Aspire components enable health checks for all services. For more information, see .NET Aspire components overview.
The .NET Aspire Milvus database component uses the configured client to perform a HealthAsync
. If the result is healthy, the health check is considered healthy, otherwise it's unhealthy. Likewise, if there's an exception, the health check is considered unhealthy with the error propagating through the health check failure.
Observability and telemetry
.NET Aspire components automatically set up Logging, Tracing, and Metrics configurations, which are sometimes known as the pillars of observability. For more information about component observability and telemetry, see .NET Aspire components overview. Depending on the backing service, some components may only support some of these features. For example, some components support logging and tracing, but not metrics. Telemetry features can also be disabled using the techniques presented in the Configuration section.
Logging
The .NET Aspire Milvus database component uses standard .NET logging, and you'll see log entries from the following category:
Milvus.Client
See also
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla