Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;

[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.ServiceBus", "5.7.0")]
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.ServiceBus", "5.9.0-alpha.20230203.1")]
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) =>
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
{
workerOption.InputConverters.RegisterAt<ServiceBusReceivedMessageConverter>(0);
});
}
}
}
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
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
{
ModelBindingData binding => ConvertToServiceBusReceivedMessage(context, binding),
_ => new ValueTask<ConversionResult>(ConversionResult.Unhandled()),
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
};
}

private ValueTask<ConversionResult> ConvertToServiceBusReceivedMessage(ConverterContext context, ModelBindingData binding)
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
{
// The lock token is a 16 byte GUID
const int lockTokenLength = 16;
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated

ReadOnlyMemory<byte> bytes = binding.Content.ToMemory();
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
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));
}
Comment thread
JoshLove-msft marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Microsoft.Azure.Functions.Worker
{
[SupportsDeferredBinding]
public sealed class ServiceBusTriggerAttribute : TriggerBindingAttribute, ISupportCardinality
{
private bool _isBatched = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@
<Description>Azure Service Bus extensions for .NET isolated functions</Description>

<!--Version information-->
<VersionPrefix>5.7.0</VersionPrefix>
<VersionPrefix>5.9.0</VersionPrefix>

<!--Temporarily opting out of documentation. Pending documentation-->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<Import Project="..\..\..\build\Extensions.props" />


<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.13.0-alpha.20230203.1" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Worker.Extensions.Abstractions\src\Worker.Extensions.Abstractions.csproj" />
<ProjectReference Include="..\..\..\src\DotNetWorker.Core\DotNetWorker.Core.csproj" />
</ItemGroup>

<ItemGroup>
<SharedReference Include="../../Worker.Extensions.Shared/Worker.Extensions.Shared.csproj" />
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions test/E2ETests/E2EApps/E2EApp/E2EApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\extensions\Worker.Extensions.ServiceBus\src\Worker.Extensions.ServiceBus.csproj" />
<ProjectReference Include="..\..\..\..\extensions\Worker.Extensions.Storage\src\Worker.Extensions.Storage.csproj" />
<ProjectReference Include="..\..\..\..\extensions\Worker.Extensions.Abstractions\src\Worker.Extensions.Abstractions.csproj" />
<ProjectReference Include="..\..\..\..\extensions\Worker.Extensions.CosmosDB\src\Worker.Extensions.CosmosDB.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Functions.Tests;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
Expand Down Expand Up @@ -244,6 +245,41 @@ void ValidateQueueOutput(ExpandoObject b)
}
}

[Fact]
public void ServiceBusTriggerFunction_SDKTypeBindings()
{
var generator = new FunctionMetadataGenerator();
var module = ModuleDefinition.ReadModule(_thisAssembly.Location);
var typeDef = TestUtility.GetTypeDefinition(typeof(ServiceBusSDKBindings));
var functions = generator.GenerateFunctionMetadata(typeDef);
var extensions = generator.Extensions;

Assert.Equal(1, functions.Count());

var serviceBusTrigger = functions.Single(p => p.Name == "ServiceBusTriggerFunction");

ValidateFunction(serviceBusTrigger, "ServiceBusTriggerFunction",
GetEntryPoint(nameof(ServiceBusSDKBindings), nameof(ServiceBusSDKBindings.ServiceBusFunction)),
b => ValidateServiceBusTrigger(b));

AssertDictionary(extensions, new Dictionary<string, string>
{
{ "Microsoft.Azure.WebJobs.Extensions.ServiceBus", "5.9.0-alpha.20230203.1" },
});

void ValidateServiceBusTrigger(ExpandoObject b)
{
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "message" },
{ "Type", "serviceBusTrigger" },
{ "Direction", "In" },
{ "queueName", "queue" },
{ "Properties", new Dictionary<String, Object>() { { "SupportsDeferredBinding", "True" } } }
});
}
}

[Fact]
public void TimerFunction()
{
Expand Down Expand Up @@ -750,6 +786,16 @@ public object BlobToBlobs(
}
}

private class ServiceBusSDKBindings
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
{
[Function("ServiceBusTriggerFunction")]
public object ServiceBusFunction(
[ServiceBusTrigger("queue")] ServiceBusReceivedMessage message)
{
throw new NotImplementedException();
}
}

private class ExternalType_Return
{
public const string FunctionName = "BasicHttpWithExternalTypeReturn";
Expand Down
1 change: 1 addition & 0 deletions test/FunctionMetadataGeneratorTests/SdkTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ProjectReference Include="..\..\extensions\Worker.Extensions.Storage\src\Worker.Extensions.Storage.csproj" />
<ProjectReference Include="..\..\extensions\Worker.Extensions.Timer\src\Worker.Extensions.Timer.csproj" />
<ProjectReference Include="..\..\extensions\Worker.Extensions.EventHubs\src\Worker.Extensions.EventHubs.csproj" />
<ProjectReference Include="..\..\extensions\Worker.Extensions.ServiceBus\src\Worker.Extensions.ServiceBus.csproj" />
<ProjectReference Include="..\..\sdk\FunctionMetadataLoaderExtension\FunctionMetadataLoaderExtension.csproj" />
<ProjectReference Include="..\..\sdk\Sdk\Sdk.csproj" />
<ProjectReference Include="..\..\src\DotNetWorker\DotNetWorker.csproj" />
Expand Down