Watch Aspire live streamsDocsTry Aspire

Get started with the Azure Web PubSub integrations

Azure Web PubSub logo

Azure Web PubSub is a fully managed real-time messaging service that enables you to build real-time web applications using WebSockets and publish-subscribe patterns. The Aspire Azure Web PubSub integration lets you model a Web PubSub service as a first-class resource in your AppHost, then hand the connection information to any consuming app — regardless of language.

Adding Azure Web PubSub through Aspire — rather than wiring up connection strings and configuration by hand — gives you:

  • Declarative resource modeling. Declare your Web PubSub service, hubs, and event handlers as typed resources in the AppHost, and let Aspire generate the Azure infrastructure for you.
  • Consistent connection info across languages. Once you reference the Web PubSub resource from a consuming app, Aspire injects the service endpoint as environment variables in a predictable format that works from C#, TypeScript, Python, Go, or any other language.
  • Role-based access by default. The hosting integration uses WebPubSubServiceOwner role assignment so your apps connect with managed identity rather than access keys.
  • Local emulator support. Aspire can run the Azure Web PubSub emulator as a container for local development, so you can develop and test real-time messaging without an Azure subscription. Publishing still provisions Azure Web PubSub. For more information, see Run Azure Web PubSub locally with the emulator.
  • Dashboard observability. The Web PubSub resource shows up in the Aspire dashboard alongside your other services.
  • A first-class C# client integration. C# apps can use the Aspire.Azure.Messaging.WebPubSub package for dependency injection, health checks, and OpenTelemetry, all wired up from the same resource name.

The Azure Web PubSub integration has two sides: a hosting integration that you use in your AppHost to model the Web PubSub resource, and a connection story for consuming apps that reference it.

AppHostConsuming appHosting integrationAzure Web PubSubHubClient integrationApp

The hosting integration lives in your AppHost project and models the Web PubSub service and its hubs as resources. The client integration lives in each consuming app and uses the connection information Aspire injects to talk to the service.

Getting there is a two-step process: model the Azure Web PubSub resources in your AppHost, then connect to the service from each app that needs it.

  1. Add the Azure Web PubSub hosting integration to your AppHost, then declare a Web PubSub resource and optional hubs, and reference them from the apps that need to send or receive real-time messages. The Azure Web PubSub Hosting integration article walks through every capability — adding hubs, event handlers, the local emulator, role assignments, existing resources, and infrastructure customization — with side-by-side C# and TypeScript examples.

    Set up Azure Web PubSub in the AppHost

  2. When you reference an Azure Web PubSub resource from a consuming app, Aspire injects its connection information as environment variables. See Connect to Azure Web PubSub for the connection properties reference and per-language examples for C#, Go, Python, and TypeScript — including the full C# client integration.

    Connect to Azure Web PubSub