Aspire.Azure.Messaging.WebPubSub
9.0.0
Prefix Reserved
This version is out of support and is no longer maintained. Please upgrade to the latest version. See our support policy for details: https://aka.ms/dotent/aspire/support
See the version list below for details.
dotnet add package Aspire.Azure.Messaging.WebPubSub --version 9.0.0
NuGet\Install-Package Aspire.Azure.Messaging.WebPubSub -Version 9.0.0
<PackageReference Include="Aspire.Azure.Messaging.WebPubSub" Version="9.0.0" />
<PackageVersion Include="Aspire.Azure.Messaging.WebPubSub" Version="9.0.0" />
<PackageReference Include="Aspire.Azure.Messaging.WebPubSub" />
paket add Aspire.Azure.Messaging.WebPubSub --version 9.0.0
#r "nuget: Aspire.Azure.Messaging.WebPubSub, 9.0.0"
#:package Aspire.Azure.Messaging.WebPubSub@9.0.0
#addin nuget:?package=Aspire.Azure.Messaging.WebPubSub&version=9.0.0
#tool nuget:?package=Aspire.Azure.Messaging.WebPubSub&version=9.0.0
Aspire.Azure.Messaging.WebPubSub
Registers a WebPubSubServiceClient in the DI container for connecting to Azure Web PubSub.
Getting started
Prerequisites
- Azure subscription - create one for free
- An existing Azure Web PubSub service instance, learn more about how to Create a Web PubSub resource. Alternatively, you can use a connection string, which is not recommended in production environments.
Install the package
Install the .NET Aspire Azure Web PubSub library with NuGet:
dotnet add package Aspire.Azure.Messaging.WebPubSub
Usage example
In the Program.cs file of your project, call the AddAzureWebPubSubHub extension method to register a WebPubSubServiceClient for use via the dependency injection container. The method takes a connection name parameter.
builder.AddAzureWebPubSubServiceClient("wps1");
You can then retrieve the WebPubSubServiceClient instance using dependency injection. For example, to retrieve the client from a Web API controller:
private readonly WebPubSubServiceClient _client;
public ProductsController(WebPubSubServiceClient client)
{
_client = client;
}
See the Azure.Messaging.WebPubSub documentation for examples on using the WebPubSubServiceClient.
Configuration
The .NET Aspire Azure Web PubSub library provides multiple options to configure the Azure Web PubSub connection based on the requirements and conventions of your project. Note that either a Endpoint or a ConnectionString is a required to be supplied.
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.AddAzureWebPubSubHub():
builder.AddAzureWebPubSubServiceClient("WebPubSubConnectionName", "your_hub_name");
And then the connection information will be retrieved from the ConnectionStrings configuration section. Two connection formats are supported:
Use the service endpoint
The recommended approach is to use the service endpoint, which works with the AzureMessagingWebPubSubSettings.Credential property to establish a connection. If no credential is configured, the DefaultAzureCredential is used.
{
"ConnectionStrings": {
"WebPubSubConnectionName": "https://xxx.webpubsub.azure.com"
}
}
Connection string
Alternatively, a connection string can be used.
{
"ConnectionStrings": {
"WebPubSubConnectionName": "Endpoint=https://xxx.webpubsub.azure.com;AccessKey==xxxxxxx"
}
}
Use configuration providers
The .NET Aspire Azure Web PubSub library supports Microsoft.Extensions.Configuration. It loads the AzureMessagingWebPubSubSettings and WebPubSubServiceClientOptions from configuration by using the Aspire:Azure:Messaging:WebPubSub key. Example appsettings.json that configures some of the options:
{
"Aspire": {
"Azure": {
"Messaging": {
"WebPubSub": {
"DisableHealthChecks": true,
"HubName": "your_hub_name"
}
}
}
}
}
Use inline delegates
You can also pass the Action<AzureMessagingWebPubSubSettings> configureSettings delegate to set up some or all the options inline, for example to disable health checks from code:
builder.AddAzureWebPubSubServiceClient("wps", settings => settings.DisableHealthChecks = true);
You can also setup the WebPubSubServiceClientOptions using the optional Action<IAzureClientBuilder<WebPubSubServiceClient, WebPubSubServiceClientOptions>> configureClientBuilder parameter of the AddAzureWebPubSubHub method. For example, to set the client ID for this client:
builder.AddAzureWebPubSubServiceClient("wps", configureClientBuilder: clientBuilder => clientBuilder.ConfigureOptions(options => options.Retry.MaxRetries = 5));
AppHost extensions
In your AppHost project, add a Web PubSub connection and consume the connection using the following methods:
var webPubSub = builder.AddAzureWebPubSub("wps");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(webPubSub);
The AddAzureWebPubSubHub method will read connection information from the AppHost's configuration (for example, from "user secrets") under the ConnectionStrings:wps config key. The WithReference method passes that connection information into a connection string named wps in the MyService project. In the Program.cs file of MyService, the connection can be consumed using:
builder.AddAzureWebPubSubServiceClient("wps");
Additional documentation
- https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/webpubsub/Azure.Messaging.WebPubSub/README.md
- https://github.com/dotnet/aspire/tree/main/src/Components/README.md
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Azure.Core (>= 1.44.1)
- Azure.Identity (>= 1.13.1)
- Azure.Messaging.WebPubSub (>= 1.4.0)
- Microsoft.Extensions.Azure (>= 1.7.6)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 9.5.2 | 236 | 10/23/2025 | |
| 9.5.1 | 417 | 10/3/2025 | |
| 9.5.0 | 363 | 9/25/2025 | |
| 9.4.2 | 363 | 9/2/2025 | |
| 9.4.1 | 302 | 8/12/2025 | |
| 9.4.0 | 273 | 7/29/2025 | |
| 9.3.1 | 763 | 6/10/2025 | |
| 9.3.0 | 426 | 5/19/2025 | |
| 9.2.1 | 565 | 4/24/2025 | |
| 9.2.0 | 1,473 | 4/10/2025 | |
| 9.1.0 | 9,554 | 2/25/2025 | |
| 9.0.0 | 3,276 | 11/12/2024 | |
| 9.0.0-rc.1.24511.1 | 702 | 10/15/2024 | |
| 8.2.2 | 338 | 10/24/2024 | |
| 8.2.1 | 754 | 9/26/2024 | |
| 8.2.0 | 866 | 8/29/2024 | |
| 8.1.0 | 1,092 | 7/23/2024 |