Microsoft.Azure.WebJobs.Extensions.WebPubSub 1.8.0
Prefix Reserveddotnet add package Microsoft.Azure.WebJobs.Extensions.WebPubSub --version 1.8.0
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.WebPubSub -Version 1.8.0
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.WebPubSub" Version="1.8.0" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.WebPubSub" Version="1.8.0" />Directory.Packages.props
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.WebPubSub" />Project file
paket add Microsoft.Azure.WebJobs.Extensions.WebPubSub --version 1.8.0
#r "nuget: Microsoft.Azure.WebJobs.Extensions.WebPubSub, 1.8.0"
#addin nuget:?package=Microsoft.Azure.WebJobs.Extensions.WebPubSub&version=1.8.0Install as a Cake Addin
#tool nuget:?package=Microsoft.Azure.WebJobs.Extensions.WebPubSub&version=1.8.0Install as a Cake Tool
Azure WebJobs Web PubSub client library for .NET
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
Getting started
Install the package
Install the Web PubSub extension withNuGet:
dotnet add package Microsoft.Azure.WebJobs.Extensions.WebPubSub
Prerequisites
You must have anAzure subscription and an Azure resource group with a Web PubSub resource. Follow thisstep-by-step tutorial to create an Azure Web PubSub instance.
Authenticate the client
In order to let the extension work with Azure Web PubSub service, you will need to provide a validConnectionString
.
You can find theKeys for you Azure Web PubSub service in theAzure Portal.
TheAzureWebJobsStorage
connection string is used to preserve the processing checkpoint information as required refer toStorage considerations
For the local development use thelocal.settings.json
file to store the connection string,<connection-string>
can be set toWebPubSubConnectionString
as default supported in the extension, or you can set customized names by mapping it withConnection = <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 theapplication settings to set the connection string.
Key concepts
Using Web PubSub input binding
Please follow theinput binding tutorial to learn about using this extension for buildingWebPubSubConnection
to create Websockets connection to service with input binding.
Using Web PubSub output binding
Please follow theoutput binding tutorial to learn about using this extension for publishing Web PubSub messages.
Using Web PubSub trigger
Please follow thetrigger binding tutorial to learn about triggering an Azure Function when an event is sent from service upstream.
InConnect
andUserEvent
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 respectConnectEventResponse
orEventErrorResponse
, and ignore other returns. WhenEventErrorResponse
is returned, service will drop client connection. Please follow thetrigger binding return value tutorial to learn about using the trigger return value.
Examples
Functions that uses Web PubSub input binding
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; }}
Functions that uses Web PubSub output binding
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)); }}
Functions that uses Web PubSub trigger
[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);}
Functions that uses Web PubSub trigger return value
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); }}
Functions that handles MQTT Client "connect" event
[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); } }}
Troubleshooting
Please refer toMonitor Azure Functions for troubleshooting guidance.
Next steps
Read theintroduction to Azure Function orcreating an Azure Function guide.
Contributing
See ourCONTRIBUTING.md for details on building,testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions requireyou to agree to a Contributor License Agreement (CLA) declaring that you havethe right to, and actually do, grant us the rights to use your contribution. Fordetails, visitcla.microsoft.com.
This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQor contactopencode@microsoft.com with anyadditional questions or comments.
Product | VersionsCompatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
.NETStandard 2.0
- Azure.Messaging.WebPubSub(>= 1.4.0)
- Microsoft.AspNetCore.Http(>= 2.1.22)
- Microsoft.Azure.WebJobs(>= 3.0.37)
- Microsoft.Azure.WebPubSub.Common(>= 1.3.0)
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 |
---|---|---|
1.8.0 | 28,375 | 9/4/2024 |
1.7.0 | 79,992 | 8/30/2023 |
1.6.0 | 6,866 | 7/13/2023 |
1.5.0 | 46,639 | 4/13/2023 |
1.4.0 | 11,397 | 2/2/2023 |
1.3.0 | 13,077 | 11/11/2022 |
1.2.0 | 38,679 | 3/10/2022 |
1.1.0 | 18,335 | 12/9/2021 |
1.0.0 | 3,062 | 11/12/2021 |
1.0.0-beta.4 | 1,475 | 10/28/2021 |
1.0.0-beta.3 | 4,722 | 7/26/2021 |
1.0.0-beta.2 | 429 | 7/15/2021 |
1.0.0-beta.1 | 3,497 | 4/27/2021 |
- Last updated9/4/2024
- Project website
- Source repository
- MIT license
- Download package (88.26 KB)
- Open in NuGet Package Explorer
Open in NuGet Trends
- Report package
© Microsoft Corporation. All rights reserved.