Skip to content

Commit 5253bde

Browse files
committed
Add NSB10 project
1 parent 882eb28 commit 5253bde

File tree

10 files changed

+261
-2
lines changed

10 files changed

+261
-2
lines changed

Snippets/ASBFunctionsWorker/ASBFunctionsWorker.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 17
3-
VisualStudioVersion = 17.0.31919.166
2+
# Visual Studio Version 18
3+
VisualStudioVersion = 18.0.11012.119 d18.0
44
MinimumVisualStudioVersion = 15.0.26730.12
55
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASBFunctionsWorker_1", "ASBFunctionsWorker_1\ASBFunctionsWorker_1.csproj", "{A491A83E-174A-4639-B55E-72ED39DD955C}"
66
EndProject
@@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASBFunctionsWorker_5", "ASB
1414
EndProject
1515
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBFunctionsWorker_6", "ASBFunctionsWorker_6\ASBFunctionsWorker_6.csproj", "{B447A2D5-2B62-4198-9519-12339CCCA403}"
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBFunctionsWorker_7", "ASBFunctionsWorker_7\ASBFunctionsWorker_7.csproj", "{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -44,6 +46,10 @@ Global
4446
{B447A2D5-2B62-4198-9519-12339CCCA403}.Debug|Any CPU.Build.0 = Debug|Any CPU
4547
{B447A2D5-2B62-4198-9519-12339CCCA403}.Release|Any CPU.ActiveCfg = Release|Any CPU
4648
{B447A2D5-2B62-4198-9519-12339CCCA403}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{A0D01DCB-8A89-A490-EDFB-A2F37CD721F8}.Release|Any CPU.Build.0 = Release|Any CPU
4753
EndGlobalSection
4854
GlobalSection(SolutionProperties) = preSolution
4955
HideSolutionNode = FALSE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Azure.Storage.Blobs" Version="12.*" />
9+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.*" />
10+
<PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="7.0.0-alpha.1" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Azure.Storage.Blobs;
4+
using Microsoft.Extensions.Hosting;
5+
using NServiceBus;
6+
7+
#region asb-function-isolated-configuration
8+
[assembly: NServiceBusTriggerFunction("WorkerDemoEndpoint")]
9+
10+
public class Program
11+
{
12+
public static Task Main()
13+
{
14+
var host = new HostBuilder()
15+
.ConfigureFunctionsWorkerDefaults()
16+
.UseNServiceBus()
17+
.Build();
18+
19+
return host.RunAsync();
20+
}
21+
}
22+
#endregion asb-function-isolated-configuration
23+
24+
class EnableDiagnostics
25+
{
26+
#region asb-function-isolated-enable-diagnostics
27+
public static Task Main()
28+
{
29+
var host = new HostBuilder()
30+
.ConfigureFunctionsWorkerDefaults()
31+
.UseNServiceBus(configuration =>
32+
{
33+
configuration.LogDiagnostics();
34+
})
35+
.Build();
36+
37+
return host.RunAsync();
38+
}
39+
#endregion
40+
}
41+
42+
class EnableDiagnosticsBlob
43+
{
44+
public static Task Main()
45+
{
46+
var endpointName = "ASBWorkerEndpoint";
47+
48+
#region asb-function-iso-diagnostics-blob
49+
var host = new HostBuilder()
50+
.ConfigureFunctionsWorkerDefaults()
51+
.UseNServiceBus(configuration =>
52+
{
53+
configuration.AdvancedConfiguration.CustomDiagnosticsWriter(
54+
async (diagnostics, cancellationToken) =>
55+
{
56+
var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
57+
var blobServiceClient = new BlobServiceClient(connectionString);
58+
59+
var containerClient = blobServiceClient.GetBlobContainerClient("diagnostics");
60+
await containerClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
61+
62+
var blobName = $"{endpointName}-configuration.txt";
63+
var blobClient = containerClient.GetBlobClient(blobName);
64+
await blobClient.UploadAsync(BinaryData.FromString(diagnostics), cancellationToken);
65+
});
66+
})
67+
.Build();
68+
#endregion
69+
return host.RunAsync();
70+
}
71+
72+
}
73+
74+
class ConfigureErrorQueue
75+
{
76+
#region asb-function-isolated-configure-error-queue
77+
public static Task Main()
78+
{
79+
var host = new HostBuilder()
80+
.ConfigureFunctionsWorkerDefaults()
81+
.UseNServiceBus(configuration =>
82+
{
83+
// Change the error queue name:
84+
configuration.AdvancedConfiguration.SendFailedMessagesTo("my-custom-error-queue");
85+
86+
// Or disable the error queue to let ASB native dead-lettering handle repeated failures:
87+
configuration.DoNotSendMessagesToErrorQueue();
88+
})
89+
.Build();
90+
91+
return host.RunAsync();
92+
}
93+
#endregion
94+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#startcode asb-function-isolated-identity-connection
2+
[assembly: NServiceBusTriggerFunction("WorkerDemoEndpoint", Connection = "MyConnectionName")]
3+
#endcode
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace ASBFunctionsWorker_5
2+
{
3+
using Microsoft.Azure.Functions.Worker;
4+
using Microsoft.Azure.Functions.Worker.Http;
5+
using NServiceBus;
6+
using System.Net;
7+
using System.Threading.Tasks;
8+
9+
#region asb-function-isolated-dispatching-outside-message-handler
10+
public class HttpTrigger
11+
{
12+
readonly IFunctionEndpoint functionEndpoint;
13+
14+
public HttpTrigger(IFunctionEndpoint functionEndpoint)
15+
{
16+
this.functionEndpoint = functionEndpoint;
17+
}
18+
19+
[Function("HttpSender")]
20+
public async Task<HttpResponseData> Run(
21+
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestData req,
22+
FunctionContext executionContext)
23+
{
24+
await functionEndpoint.Send(new TriggerMessage(), executionContext);
25+
26+
return req.CreateResponse(HttpStatusCode.OK);
27+
}
28+
}
29+
#endregion
30+
31+
class TriggerMessage
32+
{
33+
}
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.Extensions.Hosting;
3+
using NServiceBus;
4+
5+
namespace ASBFunctionsWorker_6
6+
{
7+
class TopologyOptions
8+
{
9+
public void SetTopologyOptions()
10+
{
11+
#region ASBFunctionsWorker-topology-options
12+
var host = new HostBuilder()
13+
.ConfigureFunctionsWorkerDefaults()
14+
.ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true))
15+
.UseNServiceBus()
16+
.Build();
17+
#endregion
18+
}
19+
}
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace ASBFunctionsWorker_6;
2+
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Azure.Messaging.ServiceBus;
6+
using Microsoft.Azure.Functions.Worker;
7+
using Microsoft.Extensions.Hosting;
8+
using NServiceBus;
9+
10+
#region custom-trigger-definition
11+
12+
class CustomTriggerDefinition
13+
{
14+
IFunctionEndpoint functionEndpoint;
15+
16+
public CustomTriggerDefinition(IFunctionEndpoint functionEndpoint)
17+
{
18+
this.functionEndpoint = functionEndpoint;
19+
}
20+
21+
[Function("MyCustomTrigger")]
22+
public async Task Run(
23+
[ServiceBusTrigger("MyFunctionsEndpoint")]
24+
ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions, FunctionContext context,
25+
CancellationToken cancellationToken = default)
26+
{
27+
await functionEndpoint.Process(message, messageActions, context, cancellationToken);
28+
}
29+
}
30+
31+
public class Program
32+
{
33+
public async Task Main()
34+
{
35+
var host = new HostBuilder()
36+
.ConfigureFunctionsWorkerDefaults()
37+
.UseNServiceBus("MyFunctionsEndpoint")
38+
.Build();
39+
40+
await host.RunAsync();
41+
}
42+
}
43+
44+
#endregion
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#startcode ASBFunctionsWorker-topology-migration-options-json
2+
{
3+
"AzureServiceBus": {
4+
"MigrationTopologyOptions": {
5+
"TopicToPublishTo": "TopicToPublishTo",
6+
"TopicToSubscribeOn": "TopicToSubscribeOn",
7+
"EventsToMigrateMap": [
8+
"MyNamespace.NotYetMigratedEvent"
9+
],
10+
"SubscribedEventToRuleNameMap": {
11+
"MyNamespace.NotYetMigratedEvent": "EventRuleName"
12+
},
13+
"PublishedEventToTopicsMap": {
14+
"MyNamespace.MigratedEvent": "MigratedEvent"
15+
},
16+
"SubscribedEventToTopicsMap": {
17+
"MyNamespace.MigratedEvent": "MigratedEvent"
18+
},
19+
"QueueNameToSubscriptionNameMap": {
20+
"Publisher": "PublisherSubscriptionName"
21+
}
22+
}
23+
}
24+
}
25+
#endcode
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#startcode ASBFunctionsWorker-topology-options-json
2+
{
3+
"AzureServiceBus": {
4+
"TopologyOptions": {
5+
"PublishedEventToTopicsMap": {
6+
"MyNamespace.SomeEvent": "some-event"
7+
},
8+
"SubscribedEventToTopicsMap": {
9+
"MyNamespace.SomeEvent": [
10+
"some-event",
11+
"some-other-event"
12+
]
13+
},
14+
"QueueNameToSubscriptionNameMap": {
15+
"Publisher": "PublisherSubscriptionName"
16+
}
17+
}
18+
}
19+
}
20+
#endcode

Snippets/ASBFunctionsWorker/ASBFunctionsWorker_7/prerelease.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)