Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions Snippets/ASBFunctionsWorker/ASBFunctionsWorker.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
# Visual Studio Version 18
VisualStudioVersion = 18.0.11012.119 d18.0
MinimumVisualStudioVersion = 15.0.26730.12
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASBFunctionsWorker_1", "ASBFunctionsWorker_1\ASBFunctionsWorker_1.csproj", "{A491A83E-174A-4639-B55E-72ED39DD955C}"
EndProject
Expand All @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASBFunctionsWorker_5", "ASB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBFunctionsWorker_6", "ASBFunctionsWorker_6\ASBFunctionsWorker_6.csproj", "{B447A2D5-2B62-4198-9519-12339CCCA403}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBFunctionsWorker_7", "ASBFunctionsWorker_7\ASBFunctionsWorker_7.csproj", "{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -44,6 +46,10 @@ Global
{B447A2D5-2B62-4198-9519-12339CCCA403}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B447A2D5-2B62-4198-9519-12339CCCA403}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B447A2D5-2B62-4198-9519-12339CCCA403}.Release|Any CPU.Build.0 = Release|Any CPU
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="1.*" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="1.*" />
</ItemGroup>

<ItemGroup Label="Resolves vulnerabilities">
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="5.*" />
<PackageReference Include="System.Drawing.Common" Version="4.*" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.*" />
<PackageReference Include="System.Net.Http" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.X509Certificates" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.*" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.*" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.*" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="9.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="2.*" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="2.*" />
</ItemGroup>

<ItemGroup Label="Resolves vulnerabilities">
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="5.*" />
<PackageReference Include="System.Drawing.Common" Version="4.*" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.*" />
<PackageReference Include="System.Net.Http" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.X509Certificates" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.*" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="9.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="3.*" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="3.*" />
</ItemGroup>

<ItemGroup Label="Resolves vulnerabilities">
<PackageReference Include="Azure.Identity" Version="1.*" />
<PackageReference Include="System.Drawing.Common" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.*" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="9.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="4.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="5.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="6.0.0-beta.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="6.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="7.0.0-alpha.1" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions Snippets/ASBFunctionsWorker/ASBFunctionsWorker_7/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using Microsoft.Extensions.Hosting;
using NServiceBus;

#region asb-function-isolated-configuration
[assembly: NServiceBusTriggerFunction("WorkerDemoEndpoint")]

public class Program
{
public static Task Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.UseNServiceBus()
.Build();

return host.RunAsync();
}
}
#endregion asb-function-isolated-configuration

class EnableDiagnostics
{
#region asb-function-isolated-enable-diagnostics
public static Task Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.UseNServiceBus(configuration =>
{
configuration.LogDiagnostics();
})
.Build();

return host.RunAsync();
}
#endregion
}

class EnableDiagnosticsBlob
{
public static Task Main()
{
var endpointName = "ASBWorkerEndpoint";

#region asb-function-iso-diagnostics-blob
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.UseNServiceBus(configuration =>
{
configuration.AdvancedConfiguration.CustomDiagnosticsWriter(
async (diagnostics, cancellationToken) =>
{
var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
var blobServiceClient = new BlobServiceClient(connectionString);

var containerClient = blobServiceClient.GetBlobContainerClient("diagnostics");
await containerClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);

var blobName = $"{endpointName}-configuration.txt";
var blobClient = containerClient.GetBlobClient(blobName);
await blobClient.UploadAsync(BinaryData.FromString(diagnostics), cancellationToken);
});
})
.Build();
#endregion
return host.RunAsync();
}

}

class ConfigureErrorQueue
{
#region asb-function-isolated-configure-error-queue
public static Task Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.UseNServiceBus(configuration =>
{
// Change the error queue name:
configuration.AdvancedConfiguration.SendFailedMessagesTo("my-custom-error-queue");

// Or disable the error queue to let ASB native dead-lettering handle repeated failures:
configuration.DoNotSendMessagesToErrorQueue();
})
.Build();

return host.RunAsync();
}
#endregion
}
3 changes: 3 additions & 0 deletions Snippets/ASBFunctionsWorker/ASBFunctionsWorker_7/Identity.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#startcode asb-function-isolated-identity-connection
[assembly: NServiceBusTriggerFunction("WorkerDemoEndpoint", Connection = "MyConnectionName")]
#endcode
34 changes: 34 additions & 0 deletions Snippets/ASBFunctionsWorker/ASBFunctionsWorker_7/Sending.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace ASBFunctionsWorker_5
{
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using NServiceBus;
using System.Net;
using System.Threading.Tasks;

#region asb-function-isolated-dispatching-outside-message-handler
public class HttpTrigger
{
readonly IFunctionEndpoint functionEndpoint;

public HttpTrigger(IFunctionEndpoint functionEndpoint)
{
this.functionEndpoint = functionEndpoint;
}

[Function("HttpSender")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestData req,
FunctionContext executionContext)
{
await functionEndpoint.Send(new TriggerMessage(), executionContext);

return req.CreateResponse(HttpStatusCode.OK);
}
}
#endregion

class TriggerMessage
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using NServiceBus;

namespace ASBFunctionsWorker_6
{
class TopologyOptions
{
public void SetTopologyOptions()
{
#region ASBFunctionsWorker-topology-options
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true))
.UseNServiceBus()
.Build();
#endregion
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace ASBFunctionsWorker_6;

using System.Threading;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using NServiceBus;

#region custom-trigger-definition

class CustomTriggerDefinition
{
IFunctionEndpoint functionEndpoint;

public CustomTriggerDefinition(IFunctionEndpoint functionEndpoint)
{
this.functionEndpoint = functionEndpoint;
}

[Function("MyCustomTrigger")]
public async Task Run(
[ServiceBusTrigger("MyFunctionsEndpoint")]
ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions, FunctionContext context,
CancellationToken cancellationToken = default)
{
await functionEndpoint.Process(message, messageActions, context, cancellationToken);
}
}

public class Program
{
public async Task Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.UseNServiceBus("MyFunctionsEndpoint")
.Build();

await host.RunAsync();
}
}

#endregion
Loading
Loading