Salta ai contenuti

Azure Queue Storage - Client integration

Questi contenuti non sono ancora disponibili nella tua lingua.

To get started with the Aspire Azure Queue Storage client integration, install the 📦 Aspire.Azure.Storage.Queues NuGet package:

.NET CLI — Add Aspire.Azure.Storage.Queues package
dotnet add package Aspire.Azure.Storage.Queues

In the Program.cs file of your client-consuming project, call the AddAzureQueueServiceClient extension method to register a QueueServiceClient for dependency injection. The method takes a connection name parameter:

builder.AddAzureQueueServiceClient("queues");

You can then retrieve the QueueServiceClient instance using dependency injection:

public class ExampleService(QueueServiceClient client)
{
// Use client...
}

Properties of the Azure Queue Storage resources

Section titled “Properties of the Azure Queue Storage resources”

When you use the WithReference method to pass an Azure Queue Storage resource from the AppHost project to a consuming client project, several properties are available to use in the consuming project.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called queues becomes QUEUES_URI.

The Azure Queue Storage resource exposes the following connection properties:

Property NameDescription
UriThe queue service endpoint

In emulator mode, an additional property is available:

Property NameDescription
ConnectionStringThe full connection string for the emulator

The Azure Queue Storage queue resource inherits all properties from its parent storage and adds:

Property NameDescription
QueueNameThe queue name

For example, if you reference a Queue Storage resource named queues in your AppHost project, the following environment variables will be available in the consuming project:

  • QUEUES_URI

The Azure Queue Storage integration provides multiple options to configure the QueueServiceClient.

When using a connection string from the ConnectionStrings configuration section, provide the name when calling AddAzureQueueServiceClient:

builder.AddAzureQueueServiceClient("queues");

Two connection formats are supported:

The recommended approach is to use a ServiceUri, which works with the Credential property. If no credential is configured, the DefaultAzureCredential is used:

{
"ConnectionStrings": {
"queues": "https://{account_name}.queue.core.windows.net/"
}
}

Alternatively, an Azure Storage connection string can be used:

{
"ConnectionStrings": {
"queues": "AccountName=myaccount;AccountKey=myaccountkey"
}
}

The Azure Queue Storage integration supports Microsoft.Extensions.Configuration. It loads the AzureStorageQueuesSettings and QueueClientOptions from configuration using the Aspire:Azure:Storage:Queues key. Example appsettings.json:

{
"Aspire": {
"Azure": {
"Storage": {
"Queues": {
"DisableHealthChecks": true,
"DisableTracing": false,
"ClientOptions": {
"Diagnostics": {
"ApplicationId": "myapp"
}
}
}
}
}
}
}

The Azure Queue Storage integration supports named configuration for multiple instances:

{
"Aspire": {
"Azure": {
"Storage": {
"Queues": {
"queue1": {
"DisableHealthChecks": true,
"ClientOptions": {
"Diagnostics": {
"ApplicationId": "myapp1"
}
}
},
"queue2": {
"DisableTracing": true,
"ClientOptions": {
"Diagnostics": {
"ApplicationId": "myapp2"
}
}
}
}
}
}
}
}

Use the connection names when calling AddAzureQueueServiceClient:

builder.AddAzureQueueServiceClient("queue1");
builder.AddAzureQueueServiceClient("queue2");

You can also pass the Action<AzureStorageQueuesSettings> delegate to set up options inline:

builder.AddAzureQueueServiceClient(
"queues",
settings => settings.DisableHealthChecks = true);

You can also configure the QueueClientOptions:

builder.AddAzureQueueServiceClient(
"queues",
configureClientBuilder: clientBuilder =>
clientBuilder.ConfigureOptions(
options => options.Diagnostics.ApplicationId = "myapp"));

By default, Aspire integrations enable health checks for all services. The Azure Queue Storage integration:

  • Adds the health check when DisableHealthChecks is false, which attempts to connect to the Azure Queue Storage.
  • Integrates with the /health HTTP endpoint, which specifies all registered health checks must pass for app to be considered ready to accept traffic.

The Azure Queue Storage integration uses the following log categories:

  • Azure.Core
  • Azure.Identity

The Azure Queue Storage integration emits the following tracing activities using OpenTelemetry:

  • Azure.Storage.Queues.QueueClient

The Azure Queue Storage integration currently doesn’t support metrics by default due to limitations with the Azure SDK.