![]() |
VOOZH | about |
dotnet add package Microsoft.Azure.WebJobs.Extensions.WebPubSub --version 1.10.2
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.WebPubSub -Version 1.10.2
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.WebPubSub" Version="1.10.2" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.WebPubSub" Version="1.10.2" />Directory.Packages.props
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.WebPubSub" />Project file
paket add Microsoft.Azure.WebJobs.Extensions.WebPubSub --version 1.10.2
#r "nuget: Microsoft.Azure.WebJobs.Extensions.WebPubSub, 1.10.2"
#:package Microsoft.Azure.WebJobs.Extensions.WebPubSub@1.10.2
#addin nuget:?package=Microsoft.Azure.WebJobs.Extensions.WebPubSub&version=1.10.2Install as a Cake Addin
#tool nuget:?package=Microsoft.Azure.WebJobs.Extensions.WebPubSub&version=1.10.2Install as a Cake Tool
This extension provides functionality for receiving Web PubSub webhook calls in Azure Functions, allowing you to easily write functions that respond to any event published to Web PubSub.
Source code | Package | API reference documentation | Product documentation | Samples
Install the Web PubSub extension with NuGet:
dotnet add package Microsoft.Azure.WebJobs.Extensions.WebPubSub
You must have an Azure subscription and an Azure resource group with a Web PubSub resource. Follow this step-by-step tutorial to create an Azure Web PubSub instance.
In order to let the extension work with Azure Web PubSub service, you will need to provide a valid ConnectionString.
You can find the Keys for you Azure Web PubSub service in the Azure Portal.
The AzureWebJobsStorage connection string is used to preserve the processing checkpoint information as required refer to Storage considerations
For the local development use the local.settings.json file to store the connection string, <connection-string> can be set to WebPubSubConnectionString as default supported in the extension, or you can set customized names by mapping it with Connection = <connection-string> in function binding attributes:
{
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"<connection-string>": "Endpoint=https://<webpubsub-name>.webpubsub.azure.com;AccessKey=<access-key>;Version=1.0;"
}
}
When deployed use the application settings to set the connection string.
Please follow the input binding tutorial to learn about using this extension for building WebPubSubConnection to create Websockets connection to service with input binding.
Please follow the output binding tutorial to learn about using this extension for publishing Web PubSub messages.
Please follow the trigger binding tutorial to learn about triggering an Azure Function when an event is sent from service upstream.
In Connect and UserEvent events, function will respect return values to send back service. Then service will depend on the response to proceed the request or else. The responses and events are paired. For example, Connect will only respect ConnectEventResponse or EventErrorResponse, and ignore other returns. When EventErrorResponse is returned, service will drop client connection. Please follow the trigger binding return value tutorial to learn about using the trigger return value.
public static class WebPubSubConnectionBindingFunction
{
[FunctionName("WebPubSubConnectionBindingFunction")]
public static WebPubSubConnection Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
[WebPubSubConnection(Hub = "hub", UserId = "{query.userid}", Connection = "<connection-string>")] WebPubSubConnection connection)
{
Console.WriteLine("login");
return connection;
}
}
public static class WebPubSubOutputBindingFunction
{
[FunctionName("WebPubSubOutputBindingFunction")]
public static async Task RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
[WebPubSub(Hub = "hub", Connection = "<connection-string>")] IAsyncCollector<WebPubSubAction> action)
{
await action.AddAsync(WebPubSubAction.CreateSendToAllAction("Hello Web PubSub!", WebPubSubDataType.Text));
}
}
[FunctionName("WebPubSubTriggerFunction")]
public static void Run(
ILogger logger,
[WebPubSubTrigger("hub", WebPubSubEventType.User, "message")] UserEventRequest request,
string data,
WebPubSubDataType dataType)
{
logger.LogInformation("Request from: {user}, data: {data}, dataType: {dataType}",
request.ConnectionContext.UserId, data, dataType);
}
public static class WebPubSubTriggerReturnValueFunction
{
[FunctionName("WebPubSubTriggerReturnValueFunction")]
public static UserEventResponse Run(
[WebPubSubTrigger("hub", WebPubSubEventType.User, "message")] UserEventRequest request)
{
return request.CreateResponse(BinaryData.FromString("ack"), WebPubSubDataType.Text);
}
}
[FunctionName("mqttConnect")]
public static WebPubSubEventResponse Run(
[WebPubSubTrigger("hub", WebPubSubEventType.System, "connect", ClientProtocols = WebPubSubTriggerAcceptedClientProtocols.Mqtt)] MqttConnectEventRequest request,
ILogger log)
{
if (request.ConnectionContext.ConnectionId != "attacker")
{
return request.CreateMqttResponse(request.ConnectionContext.UserId, Array.Empty<string>(), new string[] { "webpubsub.joinLeaveGroup.group1", "webpubsub.sendToGroup.group2" });
}
else
{
if (request.Mqtt.ProtocolVersion == MqttProtocolVersion.V311)
{
return request.CreateMqttV311ErrorResponse(MqttV311ConnectReturnCode.NotAuthorized);
}
else
{
return request.CreateMqttV50ErrorResponse(MqttV500ConnectReasonCode.NotAuthorized);
}
}
}
Please refer to Monitor Azure Functions for troubleshooting guidance.
Read the introduction to Azure Function or creating an Azure Function guide.
See our CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.10.2 | 834 | 6/1/2026 |
| 1.10.1 | 806 | 4/27/2026 |
| 1.10.0 | 2,418 | 1/20/2026 |
| 1.9.0 | 8,086 | 7/29/2025 |
| 1.8.0 | 33,598 | 9/4/2024 |
| 1.7.0 | 112,330 | 8/30/2023 |
| 1.6.0 | 7,268 | 7/13/2023 |
| 1.5.0 | 47,638 | 4/13/2023 |
| 1.4.0 | 11,989 | 2/2/2023 |
| 1.3.0 | 13,302 | 11/11/2022 |
| 1.2.0 | 40,976 | 3/10/2022 |
| 1.1.0 | 18,949 | 12/9/2021 |
| 1.0.0 | 3,247 | 11/12/2021 |
| 1.0.0-beta.4 | 1,573 | 10/28/2021 |
| 1.0.0-beta.3 | 4,854 | 7/26/2021 |
| 1.0.0-beta.2 | 524 | 7/15/2021 |
| 1.0.0-beta.1 | 3,596 | 4/27/2021 |