-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebPubSubFunction] Add AWPS function samples. (#22140)
# All SDK Contribution checklist: This checklist is used to make sure that common guidelines for a pull request are followed. - [ ] **Please open PR in `Draft` mode if it is:** - Work in progress or not intended to be merged. - Encountering multiple pipeline failures and working on fixes. - [ ] If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above. - [ ] **I have read the [contribution guidelines](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md).** - [ ] **The pull request does not introduce [breaking changes](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/breaking-change-rules.md).** ### [General Guidelines and Best Practices](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md#general-guidelines) - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### [Testing Guidelines](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md#testing-guidelines) - [ ] Pull request includes test coverage for the included changes. ### [SDK Generation Guidelines](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md#sdk-generation-guidelines) - [ ] The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code. (Track 2 only) - [ ] The `*.csproj` and `AssemblyInfo.cs` files have been updated with the new version of the SDK. Please double check nuget.org current release version. ## Additional management plane SDK specific contribution checklist: Note: Only applies to `Microsoft.Azure.Management.[RP]` or `Azure.ResourceManager.[RP]` - [ ] Include updated [management metadata](https://github.com/Azure/azure-sdk-for-net/tree/main/eng/mgmt/mgmtmetadata). - [ ] Update AzureRP.props to add/remove version info to maintain up to date API versions. ### Management plane SDK Troubleshooting - If this is very first SDK for a services and you are adding new service folders directly under /SDK, please add `new service` label and/or contact assigned reviewer. - If the check fails at the `Verify Code Generation` step, please ensure: - Do not modify any code in generated folders. - Do not selectively include/remove generated files in the PR. - Do use `generate.ps1/cmd` to generate this PR instead of calling `autorest` directly. Please pay attention to the @microsoft.csharp version output after running `generate.ps1`. If it is lower than current released version (2.3.82), please run it again as it should pull down the latest version. **Note: We have recently updated the PSH module called by `generate.ps1` to emit additional data. This would help reduce/eliminate the Code Verification check error. Please run following command**: `dotnet msbuild eng/mgmt.proj /t:Util /p:UtilityName=InstallPsModules` ### Old outstanding PR cleanup Please note: If PRs (including draft) has been out for more than 60 days and there are no responses from our query or followups, they will be closed to maintain a concise list for our reviewers.
- Loading branch information
Showing
6 changed files
with
154 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...icrosoft.Azure.WebJobs.Extensions.WebPubSub/samples/WebPubSubConnectionBindingFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Azure.WebJobs.Extensions.WebPubSub; | ||
|
||
namespace Microsoft.Azure.WebJobs.Samples | ||
{ | ||
#region Snippet:WebPubSubConnectionBindingFunction | ||
public static class WebPubSubConnectionBindingFunction | ||
{ | ||
[FunctionName("WebPubSubConnectionBindingFunction")] | ||
public static WebPubSubConnection Run( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req, | ||
[WebPubSubConnection(Hub = "hub", UserId = "{query.userid}")] WebPubSubConnection connection) | ||
{ | ||
Console.WriteLine("login"); | ||
return connection; | ||
} | ||
} | ||
#endregion | ||
} |
28 changes: 28 additions & 0 deletions
28
...ub/Microsoft.Azure.WebJobs.Extensions.WebPubSub/samples/WebPubSubOutputBindingFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Azure.WebJobs.Extensions.WebPubSub; | ||
|
||
namespace Microsoft.Azure.WebJobs.Samples | ||
{ | ||
#region Snippet:WebPubSubOutputBindingFunction | ||
public static class WebPubSubOutputBindingFunction | ||
{ | ||
[FunctionName("WebPubSubOutputBindingFunction")] | ||
public static async Task RunAsync( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req, | ||
[WebPubSub(Hub = "hub")] IAsyncCollector<WebPubSubOperation> operation) | ||
{ | ||
await operation.AddAsync(new SendToAll | ||
{ | ||
Message = BinaryData.FromString("Hello Web PubSub"), | ||
DataType = MessageDataType.Text | ||
}); | ||
} | ||
} | ||
#endregion | ||
} |
24 changes: 24 additions & 0 deletions
24
...ebpubsub/Microsoft.Azure.WebJobs.Extensions.WebPubSub/samples/WebPubSubTriggerFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Azure.WebJobs.Extensions.WebPubSub; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Samples | ||
{ | ||
#region Snippet:WebPubSubTriggerFunction | ||
public static class WebPubSubTriggerFunction | ||
{ | ||
[FunctionName("WebPubSubTriggerFunction")] | ||
public static void Run( | ||
ILogger logger, | ||
[WebPubSubTrigger("hub", WebPubSubEventType.User, "message")] ConnectionContext context, | ||
string message, | ||
MessageDataType dataType) | ||
{ | ||
logger.LogInformation("Request from: {user}, message: {message}, dataType: {dataType}", | ||
context.UserId, message, dataType); | ||
} | ||
} | ||
#endregion | ||
} |
24 changes: 24 additions & 0 deletions
24
...crosoft.Azure.WebJobs.Extensions.WebPubSub/samples/WebPubSubTriggerReturnValueFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Azure.WebJobs.Extensions.WebPubSub; | ||
|
||
namespace Microsoft.Azure.WebJobs.Samples | ||
{ | ||
#region Snippet:WebPubSubTriggerReturnValueFunction | ||
public static class WebPubSubTriggerReturnValueFunction | ||
{ | ||
[FunctionName("WebPubSubTriggerReturnValueFunction")] | ||
public static MessageResponse Run( | ||
[WebPubSubTrigger("hub", WebPubSubEventType.User, "message")] ConnectionContext context) | ||
{ | ||
return new MessageResponse | ||
{ | ||
Message = BinaryData.FromString("ack"), | ||
DataType = MessageDataType.Text | ||
}; | ||
} | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters