-
Notifications
You must be signed in to change notification settings - Fork 200
Add ability to bind to SBReceivedMessage #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
liliankasem
merged 16 commits into
Azure:feature/sdk-type-binding
from
JoshLove-msft:sb-received-message
May 22, 2023
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2647f1f
Add ability to bind to SBReceivedMessage
JoshLove-msft f00735c
Add assembly attribute
JoshLove-msft 948e4ae
Merge branch 'main' of https://github.com/Azure/azure-functions-dotne…
JoshLove-msft 5478413
PR fb
JoshLove-msft 2a41aed
save
JoshLove-msft 557d6fd
Merge branch 'feature/sdk-type-binding' of https://github.com/Azure/a…
JoshLove-msft a552f69
Use new attributes
JoshLove-msft ab0d1ee
Remove unintended changes and get ready for preview
JoshLove-msft 28147e5
Add sample
JoshLove-msft 0b2a210
Advertise more collection types
JoshLove-msft a38cd49
Add samples and remove IEnumerable support since it is not supported …
JoshLove-msft 3385c32
PR fb
JoshLove-msft b0bc62d
Merge branch 'feature/sdk-type-binding' of https://github.com/Azure/a…
JoshLove-msft 54efd0e
PR fb
JoshLove-msft 41f51ba
fix
JoshLove-msft 7e57462
Remove unnecessary registration
JoshLove-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
extensions/Worker.Extensions.ServiceBus/src/ServiceBusExtensionStartup.cs
This file contains hidden or 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,31 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Azure.Functions.Worker.Core; | ||
| using Microsoft.Extensions.Azure; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| [assembly: WorkerExtensionStartup(typeof(ServiceBusExtensionStartup))] | ||
|
|
||
| namespace Microsoft.Azure.Functions.Worker | ||
| { | ||
| public class ServiceBusExtensionStartup : WorkerExtensionStartup | ||
| { | ||
| public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder) | ||
| { | ||
| if (applicationBuilder == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(applicationBuilder)); | ||
| } | ||
|
|
||
| applicationBuilder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory | ||
|
|
||
| applicationBuilder.Services.Configure<WorkerOptions>((workerOption) => | ||
| { | ||
| workerOption.InputConverters.RegisterAt<ServiceBusReceivedMessageConverter>(0); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
extensions/Worker.Extensions.ServiceBus/src/ServiceBusReceivedMessageConverter.cs
This file contains hidden or 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,41 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Threading.Tasks; | ||
| using Azure.Messaging.ServiceBus; | ||
| using Azure.Messaging.ServiceBus.Primitives; | ||
| using Microsoft.Azure.Functions.Worker.Converters; | ||
| using Microsoft.Azure.Functions.Worker.Core; | ||
|
|
||
| namespace Microsoft.Azure.Functions.Worker; | ||
|
|
||
| internal class ServiceBusReceivedMessageConverter : IInputConverter | ||
| { | ||
| public ValueTask<ConversionResult> ConvertAsync(ConverterContext context) | ||
| { | ||
| if (context is null) | ||
| { | ||
| return new ValueTask<ConversionResult>(ConversionResult.Unhandled()); | ||
| } | ||
|
|
||
| return context.Source switch | ||
JoshLove-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| ModelBindingData binding => ConvertToServiceBusReceivedMessage(context, binding), | ||
| _ => new ValueTask<ConversionResult>(ConversionResult.Unhandled()), | ||
JoshLove-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
|
|
||
| private ValueTask<ConversionResult> ConvertToServiceBusReceivedMessage(ConverterContext context, ModelBindingData binding) | ||
JoshLove-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // The lock token is a 16 byte GUID | ||
| const int lockTokenLength = 16; | ||
JoshLove-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ReadOnlyMemory<byte> bytes = binding.Content.ToMemory(); | ||
JoshLove-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ReadOnlyMemory<byte> lockTokenBytes = bytes.Slice(0, lockTokenLength); | ||
| ReadOnlyMemory<byte> messageBytes = bytes.Slice(lockTokenLength, bytes.Length - lockTokenLength); | ||
| ServiceBusReceivedMessage message = ServiceBusAmqpExtensions.FromAmqpBytes(BinaryData.FromBytes(messageBytes), BinaryData.FromBytes(lockTokenBytes)); | ||
| return new ValueTask<ConversionResult>(ConversionResult.Success(message)); | ||
| } | ||
JoshLove-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.