Edit

Share via


Web PubSub bindings for Azure Functions

This set of articles explains how to authenticate, send real-time messages to clients connected to Azure Web PubSub by using Azure Web PubSub bindings in Azure Functions.

Action Type
Handle client events from Web PubSub Trigger binding
Handle client events from Web PubSub with HTTP trigger, or return client access URL and token Input binding
Invoke service APIs Output binding

Samples

Install extension

The extension NuGet package you install depends on the C# mode you're using in your function app:

Functions execute in an isolated C# worker process. To learn more, see Guide for running C# Azure Functions in an isolated worker process.

Add the extension to your project by installing this NuGet package.

Install bundle

The Web PubSub extension is part of an extension bundle, which is specified in your host.json project file. When you create a project that targets version 3.x or later, you should already have this bundle installed. To learn more, see extension bundle.

Note

The Web PubSub extensions for Java is not supported yet.

Key concepts

Diagram showing the workflow of Azure Web PubSub service working with Function Apps.

(1)-(2) WebPubSubConnection input binding with HttpTrigger to generate client connection.

(3)-(4) WebPubSubTrigger trigger binding or WebPubSubContext input binding with HttpTrigger to handle service request.

(5)-(6) WebPubSub output binding to request service do something.

Connection string settings

By default, an application setting named WebPubSubConnectionString is used to store your Web PubSub connection string. When you choose to use a different setting name for your connection, you must explicitly set that as the key name in your binding definitions. During local development, you must also add this setting to the Values collection in the the local.settings.json file.

Important

A connection string includes the authorization information required for your application to access Azure Web PubSub service. The access key inside the connection string is similar to a root password for your service. For optimal security, your function app should use managed identities when connecting to the Web PubSub service instead of using a connection string. For more information, see Authorize a managed identity request by using Microsoft Entra ID.

For details on how to configure and use Web PubSub and Azure Functions together, refer to Tutorial: Create a serverless notification app with Azure Functions and Azure Web PubSub service.

Next steps