-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update existing samples to ASB v5 (#6990)
* Update native integration sample * Update send-reply sample * Update native integration pubsub sample * Update send and receive with nservicebus sample * Mark as prerelease * Add topology migration sample to index --------- Co-authored-by: Daniel Marbach <[email protected]>
- Loading branch information
1 parent
da1c4f0
commit aa3e362
Showing
66 changed files
with
1,212 additions
and
236 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...service-bus-netstandard/native-integration-pub-sub/ASBS_5/NativeIntegrationPubSubASBS.sln
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,48 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29728.190 | ||
MinimumVisualStudioVersion = 15.0.26730.12 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{0D0EF536-3C89-4191-A0EF-C0742236FC46}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeSubscriberB", "NativeSubscriberB\NativeSubscriberB.csproj", "{D32FE422-7DA6-484C-91C2-2E48AE014040}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeSubscriberA", "NativeSubscriberA\NativeSubscriberA.csproj", "{9B7F1E99-B489-4432-923F-2C803480FC37}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeShared", "NativeShared\NativeShared.csproj", "{EF53E157-CE4B-497C-B53E-0102D4D4D7FF}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Publisher", "Publisher\Publisher.csproj", "{96A0B2AD-FEAC-4F43-9811-D99420D1CCC3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0D0EF536-3C89-4191-A0EF-C0742236FC46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0D0EF536-3C89-4191-A0EF-C0742236FC46}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0D0EF536-3C89-4191-A0EF-C0742236FC46}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0D0EF536-3C89-4191-A0EF-C0742236FC46}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D32FE422-7DA6-484C-91C2-2E48AE014040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D32FE422-7DA6-484C-91C2-2E48AE014040}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D32FE422-7DA6-484C-91C2-2E48AE014040}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D32FE422-7DA6-484C-91C2-2E48AE014040}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{9B7F1E99-B489-4432-923F-2C803480FC37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9B7F1E99-B489-4432-923F-2C803480FC37}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9B7F1E99-B489-4432-923F-2C803480FC37}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9B7F1E99-B489-4432-923F-2C803480FC37}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{EF53E157-CE4B-497C-B53E-0102D4D4D7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EF53E157-CE4B-497C-B53E-0102D4D4D7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EF53E157-CE4B-497C-B53E-0102D4D4D7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EF53E157-CE4B-497C-B53E-0102D4D4D7FF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{96A0B2AD-FEAC-4F43-9811-D99420D1CCC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{96A0B2AD-FEAC-4F43-9811-D99420D1CCC3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{96A0B2AD-FEAC-4F43-9811-D99420D1CCC3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{96A0B2AD-FEAC-4F43-9811-D99420D1CCC3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C0348CF9-2853-4649-B5A2-A29A74386A2A} | ||
EndGlobalSection | ||
EndGlobal |
11 changes: 11 additions & 0 deletions
11
...ervice-bus-netstandard/native-integration-pub-sub/ASBS_5/NativeShared/NativeShared.csproj
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<LangVersion>13.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.*" /> | ||
</ItemGroup> | ||
</Project> |
51 changes: 51 additions & 0 deletions
51
...service-bus-netstandard/native-integration-pub-sub/ASBS_5/NativeShared/TopologyManager.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,51 @@ | ||
using Azure.Messaging.ServiceBus; | ||
using Azure.Messaging.ServiceBus.Administration; | ||
|
||
namespace NativeSender | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
public static class TopologyManager | ||
{ | ||
public static async Task CreateSubscription(string connectionString, string subscriptionName, string ruleName, SqlRuleFilter sqlFilter, string topicPath, string forwardTo) | ||
{ | ||
var client = new ServiceBusAdministrationClient(connectionString); | ||
|
||
try | ||
{ | ||
await client.CreateQueueAsync(forwardTo); | ||
} | ||
catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists) | ||
{ | ||
} | ||
|
||
try | ||
{ | ||
await client.CreateTopicAsync(topicPath); | ||
} | ||
catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists) | ||
{ | ||
} | ||
|
||
try | ||
{ | ||
#region SubscriptionCreation | ||
|
||
await client.CreateSubscriptionAsync(new CreateSubscriptionOptions(topicPath, subscriptionName) | ||
{ | ||
LockDuration = TimeSpan.FromMinutes(5), | ||
EnableDeadLetteringOnFilterEvaluationExceptions = false, | ||
MaxDeliveryCount = int.MaxValue, | ||
EnableBatchedOperations = true, | ||
ForwardTo = forwardTo, | ||
}, new CreateRuleOptions(ruleName, sqlFilter)); | ||
|
||
#endregion | ||
} | ||
catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists) | ||
{ | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...-netstandard/native-integration-pub-sub/ASBS_5/NativeSubscriberA/NativeSubscriberA.csproj
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<LangVersion>13.0</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\NativeShared\NativeShared.csproj" /> | ||
<ProjectReference Include="..\Shared\Shared.csproj" /> | ||
</ItemGroup> | ||
</Project> |
72 changes: 72 additions & 0 deletions
72
...re-service-bus-netstandard/native-integration-pub-sub/ASBS_5/NativeSubscriberA/Program.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,72 @@ | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Messaging.ServiceBus; | ||
using Azure.Messaging.ServiceBus.Administration; | ||
using NativeSender; | ||
|
||
static class Program | ||
{ | ||
const string EnclosedMessageTypesHeader = "NServiceBus.EnclosedMessageTypes"; | ||
|
||
static string ConnectionString | ||
{ | ||
get | ||
{ | ||
var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"); | ||
if (string.IsNullOrWhiteSpace(connectionString)) | ||
{ | ||
throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites."); | ||
} | ||
|
||
return connectionString; | ||
} | ||
} | ||
|
||
static async Task Main() | ||
{ | ||
var queueName = "Samples.ASB.NativeIntegration.NativeSubscriberA"; | ||
|
||
Console.Title = queueName; | ||
|
||
#region EventOneSubscription | ||
await TopologyManager.CreateSubscription( | ||
ConnectionString, | ||
queueName, | ||
ruleName:"$default", | ||
sqlFilter: new TrueRuleFilter(), | ||
topicPath: "EventOne", | ||
forwardTo: queueName | ||
); | ||
#endregion | ||
|
||
var serviceBusClient = new ServiceBusClient(ConnectionString); | ||
var serviceBusProcessor = serviceBusClient.CreateProcessor("Samples.ASB.NativeIntegration.NativeSubscriberA"); | ||
|
||
serviceBusProcessor.ProcessMessageAsync += MessageHandler; | ||
serviceBusProcessor.ProcessErrorAsync += ErrorHandler; | ||
|
||
await serviceBusProcessor.StartProcessingAsync(); | ||
|
||
Console.WriteLine("Press any key to exit"); | ||
Console.ReadKey(); | ||
} | ||
|
||
static async Task MessageHandler(ProcessMessageEventArgs args) | ||
{ | ||
var messageType = (string) args.Message.ApplicationProperties[EnclosedMessageTypesHeader]; | ||
var bodyJson = Encoding.UTF8.GetString(args.Message.Body.ToArray()); | ||
|
||
Console.WriteLine($"Received: {messageType}"); | ||
Console.WriteLine(bodyJson); | ||
|
||
// complete the message. messages is deleted from the subscription. | ||
await args.CompleteMessageAsync(args.Message); | ||
} | ||
|
||
static Task ErrorHandler(ProcessErrorEventArgs args) | ||
{ | ||
Console.WriteLine(args.Exception.ToString()); | ||
return Task.CompletedTask; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...-netstandard/native-integration-pub-sub/ASBS_5/NativeSubscriberB/NativeSubscriberB.csproj
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<LangVersion>13.0</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\NativeShared\NativeShared.csproj" /> | ||
<ProjectReference Include="..\Shared\Shared.csproj" /> | ||
</ItemGroup> | ||
</Project> |
78 changes: 78 additions & 0 deletions
78
...re-service-bus-netstandard/native-integration-pub-sub/ASBS_5/NativeSubscriberB/Program.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,78 @@ | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Messaging.ServiceBus; | ||
using Azure.Messaging.ServiceBus.Administration; | ||
using NativeSender; | ||
|
||
static class Program | ||
{ | ||
const string EnclosedMessageTypesHeader = "NServiceBus.EnclosedMessageTypes"; | ||
|
||
static string ConnectionString | ||
{ | ||
get | ||
{ | ||
var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"); | ||
if (string.IsNullOrWhiteSpace(connectionString)) | ||
{ | ||
throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites."); | ||
} | ||
|
||
return connectionString; | ||
} | ||
} | ||
|
||
static async Task Main() | ||
{ | ||
var queueName = "Samples.ASB.NativeIntegration.NativeSubscriberB"; | ||
|
||
Console.Title = queueName; | ||
|
||
await TopologyManager.CreateSubscription( | ||
ConnectionString, | ||
queueName, | ||
ruleName:"$default", | ||
sqlFilter: new TrueRuleFilter(), | ||
topicPath: "EventOne", | ||
forwardTo: queueName | ||
); | ||
await TopologyManager.CreateSubscription( | ||
ConnectionString, | ||
queueName, | ||
ruleName:"$default", | ||
sqlFilter: new TrueRuleFilter(), | ||
topicPath: "EventTwo", | ||
forwardTo: queueName | ||
); | ||
|
||
var serviceBusClient = new ServiceBusClient(ConnectionString); | ||
var serviceBusProcessor = serviceBusClient.CreateProcessor(queueName); | ||
|
||
serviceBusProcessor.ProcessMessageAsync += MessageHandler; | ||
serviceBusProcessor.ProcessErrorAsync += ErrorHandler; | ||
|
||
await serviceBusProcessor.StartProcessingAsync(); | ||
|
||
Console.WriteLine("Press any key to exit"); | ||
Console.ReadKey(); | ||
} | ||
|
||
static async Task MessageHandler(ProcessMessageEventArgs args) | ||
{ | ||
var messageType = (string) args.Message.ApplicationProperties[EnclosedMessageTypesHeader]; | ||
var bodyJson = Encoding.UTF8.GetString(args.Message.Body.ToArray()); | ||
|
||
Console.WriteLine($"Received: {messageType}"); | ||
Console.WriteLine(bodyJson); | ||
|
||
// complete the message. messages is deleted from the subscription. | ||
await args.CompleteMessageAsync(args.Message); | ||
} | ||
|
||
static Task ErrorHandler(ProcessErrorEventArgs args) | ||
{ | ||
Console.WriteLine(args.Exception.ToString()); | ||
return Task.CompletedTask; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
samples/azure-service-bus-netstandard/native-integration-pub-sub/ASBS_5/Publisher/Program.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,42 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NServiceBus; | ||
|
||
Console.Title = "Publisher"; | ||
|
||
var endpointConfiguration = new EndpointConfiguration("Samples.ASB.Publisher"); | ||
|
||
endpointConfiguration.EnableInstallers(); | ||
endpointConfiguration.UseSerialization<SystemJsonSerializer>(); | ||
endpointConfiguration.Conventions().DefiningEventsAs(type => type.Name == nameof(EventTwo) || type.Name == nameof(EventOne)); | ||
|
||
|
||
var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"); | ||
if (string.IsNullOrWhiteSpace(connectionString)) | ||
{ | ||
throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites."); | ||
} | ||
|
||
var transport = new AzureServiceBusTransport(connectionString, TopicTopology.Default); | ||
endpointConfiguration.UseTransport(transport); | ||
|
||
var endpointInstance = await Endpoint.Start(endpointConfiguration); | ||
Console.WriteLine("Press any key to publish events"); | ||
Console.ReadKey(); | ||
Console.WriteLine(); | ||
|
||
await endpointInstance.Publish(new EventOne | ||
{ | ||
Content = $"{nameof(EventOne)} sample content", | ||
PublishedOnUtc = DateTime.UtcNow | ||
}); | ||
|
||
await endpointInstance.Publish(new EventTwo | ||
{ | ||
Content = $"{nameof(EventTwo)} sample content", | ||
PublishedOnUtc = DateTime.UtcNow | ||
}); | ||
|
||
Console.WriteLine("Press any key to exit"); | ||
Console.ReadKey(); | ||
await endpointInstance.Stop(); |
16 changes: 16 additions & 0 deletions
16
...zure-service-bus-netstandard/native-integration-pub-sub/ASBS_5/Publisher/Publisher.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<LangVersion>13.0</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\Shared.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="NServiceBus.Transport.AzureServiceBus" Version="5.0.0-alpha.2" /> | ||
</ItemGroup> | ||
<ItemGroup Label="Transitive dependencies"> | ||
<PackageReference Include="NServiceBus" Version="9.*" /> | ||
</ItemGroup> | ||
</Project> |
7 changes: 7 additions & 0 deletions
7
samples/azure-service-bus-netstandard/native-integration-pub-sub/ASBS_5/Shared/EventOne.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,7 @@ | ||
using System; | ||
|
||
public class EventOne | ||
{ | ||
public string Content { get; set; } | ||
public DateTime PublishedOnUtc { get; set; } | ||
} |
7 changes: 7 additions & 0 deletions
7
samples/azure-service-bus-netstandard/native-integration-pub-sub/ASBS_5/Shared/EventTwo.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,7 @@ | ||
using System; | ||
|
||
public class EventTwo | ||
{ | ||
public string Content { get; set; } | ||
public DateTime PublishedOnUtc { get; set; } | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/azure-service-bus-netstandard/native-integration-pub-sub/ASBS_5/Shared/Shared.csproj
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<LangVersion>13.0</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.*" /> | ||
</ItemGroup> | ||
</Project> |
Empty file.
Oops, something went wrong.