Skip to content

Commit 3e1e5ac

Browse files
authored
Convert ServiceBus Queue, Topic, and Subscriptions to Resources (#7515)
* Rename ServiceBus Queue and Topics to match other hosting resource classes. Also change the namespace of public types to be consistent with other Azure resources. * Convert ServiceBus Queue, Topic, and Subscriptions to Resources This allows them to be referenceable and waitable in the future. Also rename the classes and put them in the appropriate namespace. Contributes to #7407
1 parent d6f0f03 commit 3e1e5ac

File tree

20 files changed

+501
-236
lines changed

20 files changed

+501
-236
lines changed

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
.RunAsEmulator()
88
.AddHub("myhub");
99
#if !SKIP_UNSTABLE_EMULATORS
10-
var serviceBus = builder.AddAzureServiceBus("messaging").RunAsEmulator().WithQueue("myqueue");
10+
var serviceBus = builder.AddAzureServiceBus("messaging")
11+
.RunAsEmulator();
12+
serviceBus.AddServiceBusQueue("myqueue");
1113
var cosmosDb = builder.AddAzureCosmosDB("cosmosdb")
1214
.RunAsEmulator();
1315
var database = cosmosDb.AddCosmosDatabase("mydatabase");

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/aspire-manifest.json

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"principalId": ""
2727
}
2828
},
29+
"myhub": {
30+
"type": "value.v0",
31+
"connectionString": "Endpoint={eventhubs.outputs.eventHubsEndpoint};EntityPath=myhub"
32+
},
2933
"messaging": {
3034
"type": "azure.bicep.v0",
3135
"connectionString": "{messaging.outputs.serviceBusEndpoint}",
@@ -35,6 +39,10 @@
3539
"principalId": ""
3640
}
3741
},
42+
"myqueue": {
43+
"type": "value.v0",
44+
"connectionString": "{messaging.outputs.serviceBusEndpoint}"
45+
},
3846
"cosmosdb": {
3947
"type": "azure.bicep.v0",
4048
"connectionString": "{cosmosdb.outputs.connectionString}",
@@ -75,12 +83,17 @@
7583
"AzureWebJobsStorage__queueServiceUri": "{funcstorage67c6c.outputs.queueEndpoint}",
7684
"Aspire__Azure__Storage__Blobs__AzureWebJobsStorage__ServiceUri": "{funcstorage67c6c.outputs.blobEndpoint}",
7785
"Aspire__Azure__Storage__Queues__AzureWebJobsStorage__ServiceUri": "{funcstorage67c6c.outputs.queueEndpoint}",
78-
"eventhubs__fullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
79-
"Aspire__Azure__Messaging__EventHubs__EventHubProducerClient__eventhubs__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
80-
"Aspire__Azure__Messaging__EventHubs__EventHubConsumerClient__eventhubs__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
81-
"Aspire__Azure__Messaging__EventHubs__EventProcessorClient__eventhubs__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
82-
"Aspire__Azure__Messaging__EventHubs__PartitionReceiver__eventhubs__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
83-
"Aspire__Azure__Messaging__EventHubs__EventHubBufferedProducerClient__eventhubs__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
86+
"myhub__fullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
87+
"Aspire__Azure__Messaging__EventHubs__EventHubProducerClient__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
88+
"Aspire__Azure__Messaging__EventHubs__EventHubConsumerClient__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
89+
"Aspire__Azure__Messaging__EventHubs__EventProcessorClient__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
90+
"Aspire__Azure__Messaging__EventHubs__PartitionReceiver__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
91+
"Aspire__Azure__Messaging__EventHubs__EventHubBufferedProducerClient__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
92+
"Aspire__Azure__Messaging__EventHubs__EventHubProducerClient__myhub__EventHubName": "myhub",
93+
"Aspire__Azure__Messaging__EventHubs__EventHubConsumerClient__myhub__EventHubName": "myhub",
94+
"Aspire__Azure__Messaging__EventHubs__EventProcessorClient__myhub__EventHubName": "myhub",
95+
"Aspire__Azure__Messaging__EventHubs__PartitionReceiver__myhub__EventHubName": "myhub",
96+
"Aspire__Azure__Messaging__EventHubs__EventHubBufferedProducerClient__myhub__EventHubName": "myhub",
8497
"messaging__fullyQualifiedNamespace": "{messaging.outputs.serviceBusEndpoint}",
8598
"Aspire__Azure__Messaging__ServiceBus__messaging__FullyQualifiedNamespace": "{messaging.outputs.serviceBusEndpoint}",
8699
"cosmosdb__accountEndpoint": "{cosmosdb.outputs.connectionString}",
@@ -117,7 +130,7 @@
117130
"OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory",
118131
"ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true",
119132
"HTTP_PORTS": "{apiservice.bindings.http.targetPort}",
120-
"ConnectionStrings__eventhubs": "{eventhubs.connectionString}",
133+
"ConnectionStrings__myhub": "{myhub.connectionString}",
121134
"ConnectionStrings__messaging": "{messaging.connectionString}",
122135
"ConnectionStrings__cosmosdb": "{cosmosdb.connectionString}",
123136
"ConnectionStrings__queue": "{queue.connectionString}",

playground/AzureServiceBus/ServiceBus.AppHost/Program.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
using System.Text.Json.Nodes;
2-
using Aspire.Hosting.Azure.ServiceBus;
2+
using Aspire.Hosting.Azure;
33

44
var builder = DistributedApplication.CreateBuilder(args);
55

66
var serviceBus = builder.AddAzureServiceBus("sbemulator");
77

8-
serviceBus
9-
.WithQueue("queue1", queue =>
10-
{
11-
queue.DeadLetteringOnMessageExpiration = false;
12-
})
13-
.WithTopic("topic1", topic =>
8+
serviceBus.AddServiceBusQueue("queue1")
9+
.WithProperties(queue => queue.DeadLetteringOnMessageExpiration = false);
10+
11+
serviceBus.AddServiceBusTopic("topic1")
12+
.AddServiceBusSubscription("sub1")
13+
.WithProperties(subscription =>
1414
{
15-
var subscription = new ServiceBusSubscription("sub1")
16-
{
17-
MaxDeliveryCount = 10,
18-
};
19-
topic.Subscriptions.Add(subscription);
15+
subscription.MaxDeliveryCount = 10;
2016

21-
var rule = new ServiceBusRule("app-prop-filter-1")
17+
var rule = new AzureServiceBusRule("app-prop-filter-1")
2218
{
2319
CorrelationFilter = new()
2420
{
@@ -33,8 +29,7 @@
3329
}
3430
};
3531
subscription.Rules.Add(rule);
36-
})
37-
;
32+
});
3833

3934
serviceBus.RunAsEmulator(configure => configure.WithConfiguration(document =>
4035
{

playground/AzureServiceBus/ServiceBus.AppHost/aspire-manifest.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
"principalId": ""
1111
}
1212
},
13+
"queue1": {
14+
"type": "value.v0",
15+
"connectionString": "{sbemulator.outputs.serviceBusEndpoint}"
16+
},
17+
"topic1": {
18+
"type": "value.v0",
19+
"connectionString": "{sbemulator.outputs.serviceBusEndpoint}"
20+
},
21+
"sub1": {
22+
"type": "value.v0",
23+
"connectionString": "{sbemulator.outputs.serviceBusEndpoint}"
24+
},
1325
"worker": {
1426
"type": "project.v0",
1527
"path": "../ServiceBusWorker/ServiceBusWorker.csproj",

playground/bicep/BicepSample.AppHost/Program.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@
5353
// Redis takes forever to spin up...
5454
var redis = builder.AddAzureRedis("redis");
5555

56-
var serviceBus = builder.AddAzureServiceBus("sb")
57-
.WithQueue("queue1")
58-
.WithTopic("topic1", topic => topic.Subscriptions.AddRange([new("subscription1"), new("subscription2")]))
59-
.WithTopic("topic2", topic => topic.Subscriptions.Add(new("subscription1")));
56+
var serviceBus = builder.AddAzureServiceBus("sb");
57+
58+
serviceBus.AddServiceBusQueue("queue1");
59+
60+
var topic1 = serviceBus.AddServiceBusTopic("topic1");
61+
topic1.AddServiceBusSubscription("subscription1");
62+
topic1.AddServiceBusSubscription("subscription2");
63+
serviceBus.AddServiceBusTopic("topic2")
64+
.AddServiceBusSubscription("topic2sub", "subscription1");
65+
6066
var signalr = builder.AddAzureSignalR("signalr");
6167
var webpubsub = builder.AddAzureWebPubSub("wps");
6268
builder.AddProject<Projects.BicepSample_ApiService>("api")

playground/bicep/BicepSample.AppHost/aspire-manifest.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,30 @@
162162
"principalId": ""
163163
}
164164
},
165+
"queue1": {
166+
"type": "value.v0",
167+
"connectionString": "{sb.outputs.serviceBusEndpoint}"
168+
},
169+
"topic1": {
170+
"type": "value.v0",
171+
"connectionString": "{sb.outputs.serviceBusEndpoint}"
172+
},
173+
"subscription1": {
174+
"type": "value.v0",
175+
"connectionString": "{sb.outputs.serviceBusEndpoint}"
176+
},
177+
"subscription2": {
178+
"type": "value.v0",
179+
"connectionString": "{sb.outputs.serviceBusEndpoint}"
180+
},
181+
"topic2": {
182+
"type": "value.v0",
183+
"connectionString": "{sb.outputs.serviceBusEndpoint}"
184+
},
185+
"topic2sub": {
186+
"type": "value.v0",
187+
"connectionString": "{sb.outputs.serviceBusEndpoint}"
188+
},
165189
"signalr": {
166190
"type": "azure.bicep.v0",
167191
"connectionString": "Endpoint=https://{signalr.outputs.hostName};AuthType=azure",

playground/bicep/BicepSample.AppHost/sb.module.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource topic2 'Microsoft.ServiceBus/namespaces/topics@2024-01-01' = {
5656
parent: sb
5757
}
5858

59-
resource subscription1 'Microsoft.ServiceBus/namespaces/topics/subscriptions@2024-01-01' = {
59+
resource topic2sub 'Microsoft.ServiceBus/namespaces/topics/subscriptions@2024-01-01' = {
6060
name: 'subscription1'
6161
parent: topic2
6262
}

playground/cdk/CdkSample.AppHost/Program.cs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,36 @@
5151
var pgsql2 = builder.AddAzurePostgresFlexibleServer("pgsql2")
5252
.AddDatabase("pgsql2db");
5353

54-
var sb = builder.AddAzureServiceBus("servicebus")
55-
.WithQueue("queue1")
56-
.ConfigureInfrastructure(infrastructure =>
57-
{
58-
var queue = infrastructure.GetProvisionableResources().OfType<ServiceBusQueue>().Single(q => q.BicepIdentifier == "queue1");
59-
queue.MaxDeliveryCount = 5;
60-
queue.LockDuration = TimeSpan.FromMinutes(5);
61-
})
62-
.WithTopic("topic1")
63-
.ConfigureInfrastructure(infrastructure =>
64-
{
65-
var topic = infrastructure.GetProvisionableResources().OfType<ServiceBusTopic>().Single(q => q.BicepIdentifier == "topic1");
66-
topic.EnablePartitioning = true;
67-
})
68-
.WithTopic("topic2", topic2 => topic2.Subscriptions.Add(new("subscription1")))
69-
.ConfigureInfrastructure(infrastructure =>
70-
{
71-
var subscription = infrastructure.GetProvisionableResources().OfType<ServiceBusSubscription>().Single(q => q.BicepIdentifier == "subscription1");
72-
subscription.LockDuration = TimeSpan.FromMinutes(5);
73-
subscription.RequiresSession = true;
74-
})
75-
.WithTopic("topic1", topic2 => topic2.Subscriptions.Add(new("subscription2")))
76-
.WithTopic("topic3", topic3 => topic3.Subscriptions.AddRange([new("sub1"), new("sub2")]));
54+
var sb = builder.AddAzureServiceBus("servicebus");
55+
56+
sb.AddServiceBusQueue("queue1");
57+
sb.ConfigureInfrastructure(infrastructure =>
58+
{
59+
var queue = infrastructure.GetProvisionableResources().OfType<ServiceBusQueue>().Single(q => q.BicepIdentifier == "queue1");
60+
queue.MaxDeliveryCount = 5;
61+
queue.LockDuration = TimeSpan.FromMinutes(5);
62+
});
63+
64+
sb.AddServiceBusTopic("topic1")
65+
.AddServiceBusSubscription("subscription2");
66+
sb.ConfigureInfrastructure(infrastructure =>
67+
{
68+
var topic = infrastructure.GetProvisionableResources().OfType<ServiceBusTopic>().Single(q => q.BicepIdentifier == "topic1");
69+
topic.EnablePartitioning = true;
70+
});
71+
72+
sb.AddServiceBusTopic("topic2")
73+
.AddServiceBusSubscription("subscription1");
74+
sb.ConfigureInfrastructure(infrastructure =>
75+
{
76+
var subscription = infrastructure.GetProvisionableResources().OfType<ServiceBusSubscription>().Single(q => q.BicepIdentifier == "subscription1");
77+
subscription.LockDuration = TimeSpan.FromMinutes(5);
78+
subscription.RequiresSession = true;
79+
});
80+
81+
var topic3 = sb.AddServiceBusTopic("topic3");
82+
topic3.AddServiceBusSubscription("sub1");
83+
topic3.AddServiceBusSubscription("sub2");
7784

7885
var appConfig = builder.AddAzureAppConfiguration("appConfig");
7986

playground/cdk/CdkSample.AppHost/aspire-manifest.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@
144144
"principalId": ""
145145
}
146146
},
147+
"queue1": {
148+
"type": "value.v0",
149+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
150+
},
151+
"topic1": {
152+
"type": "value.v0",
153+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
154+
},
155+
"subscription2": {
156+
"type": "value.v0",
157+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
158+
},
159+
"topic2": {
160+
"type": "value.v0",
161+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
162+
},
163+
"subscription1": {
164+
"type": "value.v0",
165+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
166+
},
167+
"topic3": {
168+
"type": "value.v0",
169+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
170+
},
171+
"sub1": {
172+
"type": "value.v0",
173+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
174+
},
175+
"sub2": {
176+
"type": "value.v0",
177+
"connectionString": "{servicebus.outputs.serviceBusEndpoint}"
178+
},
147179
"appConfig": {
148180
"type": "azure.bicep.v0",
149181
"connectionString": "{appConfig.outputs.appConfigEndpoint}",

src/Aspire.Hosting.Azure.ServiceBus/ServiceBusCorrelationFilter.cs renamed to src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusCorrelationFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Aspire.Hosting.Azure.ServiceBus;
4+
namespace Aspire.Hosting.Azure;
55

66
/// <summary>
77
/// Represents the correlation filter expression.
88
/// </summary>
9-
public class ServiceBusCorrelationFilter
9+
public class AzureServiceBusCorrelationFilter
1010
{
1111
/// <summary>
1212
/// Represents the correlation filter expression.
1313
/// </summary>
14-
public ServiceBusCorrelationFilter()
14+
public AzureServiceBusCorrelationFilter()
1515
{
1616
}
1717

0 commit comments

Comments
 (0)