Skip to content

Commit 5dffc0c

Browse files
Update snippets absdb asq (#7727)
* Add new snippets for ABSDataBus 7 * Remove unnecessary package references. * Add NSB10 snippets for AzureServiceBus Transport * Add NSB10 snippets for Azure Table Persistence * Add NSB10 snippets for AzureStorageQueues Transport * Add prerelease.txt * Remove unnecessary empty snippet entries for ASQ
1 parent fcbdb4b commit 5dffc0c

35 files changed

+1356
-25
lines changed

Snippets/ABSDataBus/ABSDataBus.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ABSDataBus_5", "ABSDataBus_
88
EndProject
99
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ABSDataBus_6", "ABSDataBus_6\ABSDataBus_6.csproj", "{8CCD3913-9F36-4177-9A25-C5F714B97A78}"
1010
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ABSDataBus_7", "ABSDataBus_7\ABSDataBus_7.csproj", "{6BEFC972-C387-B853-92D0-A296395F9E28}"
12+
EndProject
1113
Global
1214
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1315
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +28,10 @@ Global
2628
{8CCD3913-9F36-4177-9A25-C5F714B97A78}.Debug|Any CPU.Build.0 = Debug|Any CPU
2729
{8CCD3913-9F36-4177-9A25-C5F714B97A78}.Release|Any CPU.ActiveCfg = Release|Any CPU
2830
{8CCD3913-9F36-4177-9A25-C5F714B97A78}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{6BEFC972-C387-B853-92D0-A296395F9E28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{6BEFC972-C387-B853-92D0-A296395F9E28}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{6BEFC972-C387-B853-92D0-A296395F9E28}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{6BEFC972-C387-B853-92D0-A296395F9E28}.Release|Any CPU.Build.0 = Release|Any CPU
2935
EndGlobalSection
3036
GlobalSection(SolutionProperties) = preSolution
3137
HideSolutionNode = FALSE

Snippets/ABSDataBus/ABSDataBus_4/ABSDataBus_4.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<TargetFramework>net48</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageReference Include="Azure.Identity" Version="1.*" />
76
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.*" />
87
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.*" />
98
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="4.*" />

Snippets/ABSDataBus/ABSDataBus_5/ABSDataBus_5.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="5.*" />
7-
<PackageReference Include="Azure.Identity" Version="1.*" />
87
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.*" />
98
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.*" />
109
</ItemGroup>

Snippets/ABSDataBus/ABSDataBus_6/ABSDataBus_6.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Azure.Identity" Version="1.*" />
98
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.*" />
109
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.*" />
1110
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="6.0.*" />
1211
</ItemGroup>
1312

14-
<ItemGroup Label="Resolves vulnerabilities">
15-
<PackageReference Include="System.Formats.Asn1" Version="8.*" />
16-
</ItemGroup>
17-
1813
</Project>
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="Microsoft.Extensions.Azure" Version="1.*" />
9+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0-preview.6.25358.103" />
10+
<PackageReference Include="NServiceBus.DataBus.AzureBlobStorage" Version="7.0.0-alpha.1" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using Azure.Identity;
3+
using Azure.Storage.Blobs;
4+
using Microsoft.Extensions.Azure;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Hosting;
7+
using NServiceBus;
8+
using NServiceBus.ClaimCheck.AzureBlobStorage;
9+
10+
class Usage
11+
{
12+
Usage(EndpointConfiguration endpointConfiguration)
13+
{
14+
#region AzureDataBus
15+
16+
endpointConfiguration.UseClaimCheck<AzureClaimCheck, SystemJsonClaimCheckSerializer>();
17+
18+
#endregion
19+
20+
#region AzureDataBusConfigureServiceClient
21+
22+
var serviceClient = new BlobServiceClient("connectionString");
23+
endpointConfiguration.UseClaimCheck<AzureClaimCheck, SystemJsonClaimCheckSerializer>()
24+
.UseBlobServiceClient(serviceClient);
25+
26+
#endregion
27+
28+
#region AzureDataBusInjectServiceClient
29+
30+
endpointConfiguration.UseClaimCheck<AzureClaimCheck, SystemJsonClaimCheckSerializer>();
31+
endpointConfiguration.RegisterComponents(services => services.AddSingleton<IProvideBlobServiceClient, CustomProvider>());
32+
33+
#endregion
34+
35+
#region AzureDataBusConnectionAndContainer
36+
37+
endpointConfiguration.UseClaimCheck<AzureClaimCheck, SystemJsonClaimCheckSerializer>()
38+
.ConnectionString("connectionString")
39+
.Container("containerName");
40+
41+
#endregion
42+
}
43+
44+
void UsageManagedIdentity(EndpointConfiguration endpointConfiguration, IHostApplicationBuilder builder)
45+
{
46+
#region AzureDataBusManagedIdentityServiceClient
47+
48+
var serviceClient = new BlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"), new DefaultAzureCredential());
49+
endpointConfiguration.UseClaimCheck<AzureClaimCheck, SystemJsonClaimCheckSerializer>()
50+
.UseBlobServiceClient(serviceClient);
51+
52+
#endregion
53+
54+
#region AzureDataBusManagedIdentityExtensions
55+
56+
builder.Services.AddAzureClients(azureClients =>
57+
{
58+
azureClients.AddBlobServiceClient(new Uri("https://<account-name>.blob.core.windows.net"));
59+
azureClients.UseCredential(new DefaultAzureCredential());
60+
});
61+
builder.Services.AddSingleton<IProvideBlobServiceClient, CustomProvider>();
62+
63+
#endregion
64+
}
65+
66+
#region CustomBlobServiceClientProvider
67+
68+
public class CustomProvider : IProvideBlobServiceClient
69+
{
70+
// Leverage dependency injection to use a custom-configured BlobServiceClient
71+
public CustomProvider(BlobServiceClient serviceClient)
72+
{
73+
Client = serviceClient;
74+
}
75+
76+
public BlobServiceClient Client { get; }
77+
}
78+
79+
#endregion
80+
81+
void Complex(EndpointConfiguration endpointConfiguration)
82+
{
83+
var azureStorageConnectionString = "";
84+
var basePathWithinContainer = "";
85+
var containerName = "";
86+
var maxNumberOfRetryAttempts = 3;
87+
// number of parallel operations that may proceed.
88+
var numberOfIoThreads = 3;
89+
// number of blocks that may be simultaneously uploaded when uploading a blob that is greater than the value specified by the
90+
var backOffIntervalBetweenRetriesInSecs = 1000;
91+
var renewFiveMinutesBeforeTokenExpires = TimeSpan.FromMinutes(5);
92+
93+
#region AzureDataBusSetup
94+
95+
var dataBus = endpointConfiguration.UseClaimCheck<AzureClaimCheck, SystemJsonClaimCheckSerializer>();
96+
dataBus.ConnectionString(azureStorageConnectionString);
97+
dataBus.Container(containerName);
98+
dataBus.BasePath(basePathWithinContainer);
99+
dataBus.MaxRetries(maxNumberOfRetryAttempts);
100+
dataBus.NumberOfIOThreads(numberOfIoThreads);
101+
dataBus.BackOffInterval(backOffIntervalBetweenRetriesInSecs);
102+
103+
#endregion
104+
}
105+
}

Snippets/ABSDataBus/ABSDataBus_7/prerelease.txt

Whitespace-only changes.

Snippets/ASBS/ASBS.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBS_4", "ASBS_4\ASBS_4.csp
1717
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBS_5", "ASBS_5\ASBS_5.csproj", "{6CA4021C-42C5-45F3-9AFA-50A6DBA42BAE}"
1919
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASBS_6", "ASBS_6\ASBS_6.csproj", "{1557770B-EB0D-4F49-47E5-0A37CCF18548}"
21+
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,10 @@ Global
5153
{6CA4021C-42C5-45F3-9AFA-50A6DBA42BAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
5254
{6CA4021C-42C5-45F3-9AFA-50A6DBA42BAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
5355
{6CA4021C-42C5-45F3-9AFA-50A6DBA42BAE}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{1557770B-EB0D-4F49-47E5-0A37CCF18548}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{1557770B-EB0D-4F49-47E5-0A37CCF18548}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{1557770B-EB0D-4F49-47E5-0A37CCF18548}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{1557770B-EB0D-4F49-47E5-0A37CCF18548}.Release|Any CPU.Build.0 = Release|Any CPU
5460
EndGlobalSection
5561
GlobalSection(SolutionProperties) = preSolution
5662
HideSolutionNode = FALSE

Snippets/ASBS/ASBS_6/ASBS_6.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="Azure.Identity" Version="1.15.0" />
7+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
8+
<PackageReference Include="NServiceBus.Transport.AzureServiceBus" Version="6.0.0-alpha.1" />
9+
<PackageReference Include="NUnit" Version="4.4.0" />
10+
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Azure.Messaging.ServiceBus;
2+
using NServiceBus;
3+
using NServiceBus.Pipeline;
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
public class AccessToNativeMessage
8+
{
9+
#region access-native-incoming-message
10+
11+
class DoNotAttemptMessageProcessingIfMessageIsNotLocked : Behavior<ITransportReceiveContext>
12+
{
13+
public override Task Invoke(ITransportReceiveContext context, Func<Task> next)
14+
{
15+
var lockedUntilUtc = context.Extensions.Get<ServiceBusReceivedMessage>().LockedUntil;
16+
17+
if (lockedUntilUtc <= DateTime.UtcNow)
18+
{
19+
return next();
20+
}
21+
22+
throw new Exception($"Message lock lost for MessageId {context.Message.MessageId} and it cannot be processed.");
23+
}
24+
}
25+
26+
#endregion
27+
28+
class AccessOutgoingNativeMessage
29+
{
30+
async Task AccessNativeOutgoingMessageFromHandler(IMessageHandlerContext context)
31+
{
32+
#region access-native-outgoing-message
33+
// send a command
34+
var sendOptions = new SendOptions();
35+
sendOptions.CustomizeNativeMessage(m => m.Subject = "custom-label");
36+
await context.Send(new MyCommand(), sendOptions);
37+
38+
// publish an event
39+
var publishOptions = new PublishOptions();
40+
publishOptions.CustomizeNativeMessage(m => m.Subject = "custom-label");
41+
await context.Publish(new MyEvent(), publishOptions);
42+
#endregion
43+
}
44+
45+
void Customize(AzureServiceBusTransport transport)
46+
{
47+
#region access-native-outgoing-message-over-transport
48+
transport.OutgoingNativeMessageCustomization = (operation, message) =>
49+
{
50+
// Customize the outgoing message based on the operation
51+
};
52+
#endregion
53+
}
54+
55+
class MyCommand { }
56+
class MyEvent { }
57+
}
58+
}

0 commit comments

Comments
 (0)