title | description | ms.topic | ms.date |
---|---|---|---|
.NET Aspire Milvus database component |
This article describes the .NET Aspire Milvus database component. |
how-to |
07/23/2024 |
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.
- Milvus server and connection string for accessing the server API endpoint.
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
<PackageReference Include="Aspire.Milvus.Client"
Version="[SelectVersion]" />
For more information, see dotnet add package or Manage package dependencies in .NET applications.
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");
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
<PackageReference Include="Aspire.Hosting.Milvus"
Version="[SelectVersion]" />
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");
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.
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.
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!@#$%"
}
}
}
}
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!@#$%");
[!INCLUDE component-health-checks]
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.
[!INCLUDE component-observability-and-telemetry]
The .NET Aspire Milvus database component uses standard .NET logging, and you'll see log entries from the following category:
Milvus.Client