diff --git a/docs/database/includes/cosmos-app-host.md b/docs/database/includes/cosmos-app-host.md index 27422a3f3f..a292eb65de 100644 --- a/docs/database/includes/cosmos-app-host.md +++ b/docs/database/includes/cosmos-app-host.md @@ -65,7 +65,7 @@ The preceding Bicep is a module that provisions an Azure Cosmos DB account with - `consistencyPolicy`: The consistency policy of the Cosmos DB account. The default is `Session`. - `locations`: The locations for the Cosmos DB account. The default is the resource group's location. -In addition to the Cosmos DB account, it also provisions an Azure Key Vault resource. This is used to store the Cosmos DB account's connection string securely. The generated Bicep is a starting point and can be customized to meet your specific requirements. +In addition to the Cosmos DB account, it also adds the current application to the `Data Contributor` role for the Cosmos DB account. The generated Bicep is a starting point and can be customized to meet your specific requirements. #### Customize provisioning infrastructure @@ -115,21 +115,18 @@ The dependent resource can access the injected connection string by calling the ### Add Azure Cosmos DB database resource -To add an Azure Cosmos DB database resource, chain a call on an `IResourceBuilder` to the API: +To add an Azure Cosmos DB database resource, chain a call on an `IResourceBuilder` to the API: ```csharp var builder = DistributedApplication.CreateBuilder(args); -var cosmos = builder.AddAzureCosmosDB("cosmos-db") - .AddDatabase("db"); +var cosmos = builder.AddAzureCosmosDB("cosmos-db"); +cosmos.AddCosmosDatabase("db"); // After adding all resources, run the app... ``` -When you call `AddDatabase`, it configures your Cosmos DB resources to have a database named `db`. The database is created in the Cosmos DB account that's represented by the `AzureCosmosDBResource` that you added earlier. The database is a logical container for collections and users. For more information, see [Databases, containers, and items in Azure Cosmos DB](/azure/cosmos-db/resource-model). - -> [!NOTE] -> When using the `AddDatabase` API to add a database to an Azure Cosmos DB resource, if you're running the emulator, the database isn't actually created in the emulator. This API is intended to include a database in the [Bicep generated](#generated-provisioning-bicep) by the provisioning infrastructure. +When you call `AddCosmosDatabase`, it configures your Cosmos DB resources to have a database named `db`. The database is created in the Cosmos DB account that's represented by the `AzureCosmosDBResource` that you added earlier. The database is a logical container for collections and users. For more information, see [Databases, containers, and items in Azure Cosmos DB](/azure/cosmos-db/resource-model). ### Add Azure Cosmos DB emulator resource diff --git a/docs/messaging/azure-event-hubs-integration.md b/docs/messaging/azure-event-hubs-integration.md index 4d5b3118aa..383f8b81f0 100644 --- a/docs/messaging/azure-event-hubs-integration.md +++ b/docs/messaging/azure-event-hubs-integration.md @@ -38,13 +38,13 @@ For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-pac ### Add an Azure Event Hubs resource -To add an to your app host project, call the method providing a name, and then chain a call to : +To add an to your app host project, call the method providing a name, and then call : ```csharp var builder = DistributedApplication.CreateBuilder(args); -var eventHubs = builder.AddAzureEventHubs("event-hubs") - .AddHub("messages"); +var eventHubs = builder.AddAzureEventHubs("event-hubs"); +eventHubs.AddHub("messages"); builder.AddProject() .WithReference(eventHubs); @@ -79,8 +79,9 @@ The preceding Bicep is a module that provisions an Azure Event Hubs resource wit - `sku`: The SKU of the Event Hubs resource, defaults to `Standard`. - `principalId`: The principal ID of the Event Hubs resource. - `principalType`: The principal type of the Event Hubs resource. -- `event_hubs`: The Event Hubs resource. +- `event_hubs`: The Event Hubs namespace resource. - `event_hubs_AzureEventHubsDataOwner`: The Event Hubs resource owner, based on the build-in `Azure Event Hubs Data Owner` role. For more information, see [Azure Event Hubs Data Owner](/azure/role-based-access-control/built-in-roles/analytics#azure-event-hubs-data-owner). +- `messages`: The Event Hub resource. - `eventHubsEndpoint`: The endpoint of the Event Hubs resource. The generated Bicep is a starting point and can be customized to meet your specific requirements. @@ -139,8 +140,9 @@ To add a consumer group, chain a call on an `IResourceBuilder() .WithReference(eventHubs); @@ -148,7 +150,7 @@ builder.AddProject() // After adding all resources, run the app... ``` -When you call `AddConsumerGroup`, it configures your Event Hubs resource to have a consumer group named `messages`. The consumer group is created in the Azure Event Hubs namespace that's represented by the `AzureEventHubsResource` that you added earlier. For more information, see [Azure Event Hubs: Consumer groups](/azure/event-hubs/event-hubs-features#consumer-groups). +When you call `AddConsumerGroup`, it configures your `messages` Event Hub resource to have a consumer group named `messagesConsumer`. The consumer group is created in the Azure Event Hubs namespace that's represented by the `AzureEventHubsResource` that you added earlier. For more information, see [Azure Event Hubs: Consumer groups](/azure/event-hubs/event-hubs-features#consumer-groups). ### Add Azure Event Hubs emulator resource @@ -160,9 +162,10 @@ To run the Event Hubs resource as an emulator, call the () .WithReference(eventHubs); @@ -189,12 +192,13 @@ The port that it's listening on is dynamic by default. When the container starts var builder = DistributedApplication.CreateBuilder(args); var eventHubs = builder.AddAzureEventHubs("event-hubs") - .AddHub("messages") .RunAsEmulator(emulator => { emulator.WithHostPort(7777); }); +eventHubs.AddHub("messages"); + builder.AddProject() .WithReference(eventHubs); @@ -215,12 +219,13 @@ To add a data volume to the Event Hubs emulator resource, call the { emulator.WithDataVolume(); }); +eventHubs.AddHub("messages"); + builder.AddProject() .WithReference(eventHubs); @@ -237,12 +242,13 @@ The add a bind mount to the Event Hubs emulator container, chain a call to the < var builder = DistributedApplication.CreateBuilder(args); var eventHubs = builder.AddAzureEventHubs("event-hubs") - .AddHub("messages") .RunAsEmulator(emulator => { emulator.WithDataBindMount("/path/to/data"); }); +eventHubs.AddHub("messages"); + builder.AddProject() .WithReference(eventHubs); @@ -263,12 +269,13 @@ To provide a custom JSON configuration file, call the { emulator.WithConfigurationFile("./messaging/custom-config.json"); }); +eventHubs.AddHub("messages"); + builder.AddProject() .WithReference(eventHubs); @@ -281,7 +288,6 @@ The preceding code configures the Event Hubs emulator container to use a custom var builder = DistributedApplication.CreateBuilder(args); var eventHubs = builder.AddAzureEventHubs("event-hubs") - .AddHub("messages") .RunAsEmulator(emulator => { emulator.WithConfiguration( @@ -295,6 +301,8 @@ var eventHubs = builder.AddAzureEventHubs("event-hubs") }); }); +eventHubs.AddHub("messages"); + builder.AddProject() .WithReference(eventHubs); diff --git a/docs/messaging/azure-service-bus-integration.md b/docs/messaging/azure-service-bus-integration.md index c46e2e32a0..638a1702ab 100644 --- a/docs/messaging/azure-service-bus-integration.md +++ b/docs/messaging/azure-service-bus-integration.md @@ -124,70 +124,68 @@ The dependent resource can access the injected connection string by calling the ### Add Azure Service Bus queue -To add an Azure Service Bus queue, chain a call on an `IResourceBuilder` to the API: +To add an Azure Service Bus queue, call the method on the `IResourceBuilder`: ```csharp var builder = DistributedApplication.CreateBuilder(args); -var serviceBus = builder.AddAzureServiceBus("messaging") - .WithQueue("queue"); +var serviceBus = builder.AddAzureServiceBus("messaging"); +serviceBus.AddServiceBusQueue("queue"); // After adding all resources, run the app... ``` -When you call `WithQueue`, it configures your Service Bus resources to have a queue named `queue`. The queue is created in the Service Bus namespace that's represented by the `AzureServiceBusResource` that you added earlier. For more information, see [Queues, topics, and subscriptions in Azure Service Bus](/azure/service-bus-messaging/service-bus-queues-topics-subscriptions). +When you call `AddServiceBusQueue`, it configures your Service Bus resources to have a queue named `queue`. The queue is created in the Service Bus namespace that's represented by the `AzureServiceBusResource` that you added earlier. For more information, see [Queues, topics, and subscriptions in Azure Service Bus](/azure/service-bus-messaging/service-bus-queues-topics-subscriptions). ### Add Azure Service Bus topic and subscription -To add an Azure Service Bus topic, chain a call on an `>` to the API: +To add an Azure Service Bus topic, call the method on the `IResourceBuilder`: ```csharp var builder = DistributedApplication.CreateBuilder(args); -var serviceBus = builder.AddAzureServiceBus("messaging") - .WithTopic("topic"); +var serviceBus = builder.AddAzureServiceBus("messaging"); +serviceBus.AddServiceBusTopic("topic"); // After adding all resources, run the app... ``` -When you call `WithTopic`, it configures your Service Bus resources to have a topic named `topic`. The topic is created in the Service Bus namespace that's represented by the `AzureServiceBusResource` that you added earlier. +When you call `AddServiceBusTopic`, it configures your Service Bus resources to have a topic named `topic`. The topic is created in the Service Bus namespace that's represented by the `AzureServiceBusResource` that you added earlier. -To configure a subscription for the topic, use the overload API: +To add a subscription for the topic, call the method on the `IResourceBuilder` and configure it using the method: ```csharp +using Aspire.Hosting.Azure; + var builder = DistributedApplication.CreateBuilder(args); -var serviceBus = builder.AddAzureServiceBus("messaging") - .WithTopic("topic", topic => - { - var subscription = new ServiceBusSubscription("sub1") - { - MaxDeliveryCount = 10, - Rules = - { - new ServiceBusRule("app-prop-filter-1") - { - CorrelationFilter = new() - { - ContentType = "application/text", - CorrelationId = "id1", - Subject = "subject1", - MessageId = "msgid1", - ReplyTo = "someQueue", - ReplyToSessionId = "sessionId", - SessionId = "session1", - SendTo = "xyz" - } - } - } - }; - topic.Subscriptions.Add(subscription); - }); +var serviceBus = builder.AddAzureServiceBus("messaging"); +var topic = serviceBus.AddServiceBusTopic("topic"); +topic.AddServiceBusSubscription("sub1") + .WithProperties(subscription => + { + subscription.MaxDeliveryCount = 10; + subscription.Rules.Add( + new AzureServiceBusRule("app-prop-filter-1") + { + CorrelationFilter = new() + { + ContentType = "application/text", + CorrelationId = "id1", + Subject = "subject1", + MessageId = "msgid1", + ReplyTo = "someQueue", + ReplyToSessionId = "sessionId", + SessionId = "session1", + SendTo = "xyz" + } + }); + }); // After adding all resources, run the app... ``` -The preceding code not only adds a topic, but creates and configures a subscription named `sub1` for the topic. The subscription has a maximum delivery count of `10` and a rule named `app-prop-filter-1`. The rule is a correlation filter that filters messages based on the `ContentType`, `CorrelationId`, `Subject`, `MessageId`, `ReplyTo`, `ReplyToSessionId`, `SessionId`, and `SendTo` properties. +The preceding code not only adds a topic and creates and configures a subscription named `sub1` for the topic. The subscription has a maximum delivery count of `10` and a rule named `app-prop-filter-1`. The rule is a correlation filter that filters messages based on the `ContentType`, `CorrelationId`, `Subject`, `MessageId`, `ReplyTo`, `ReplyToSessionId`, `SessionId`, and `SendTo` properties. For more information, see [Queues, topics, and subscriptions in Azure Service Bus](/azure/service-bus-messaging/service-bus-queues-topics-subscriptions). diff --git a/docs/snippets/azure/AppHost/Program.cs b/docs/snippets/azure/AppHost/Program.cs index 190ee8b8d0..f24a82417c 100644 --- a/docs/snippets/azure/AppHost/Program.cs +++ b/docs/snippets/azure/AppHost/Program.cs @@ -5,7 +5,7 @@ builder.AddAzureAppConfiguration("config"); builder.AddAzureApplicationInsights("app-insights"); builder.AddAzureCosmosDB("cosmos"); -builder.AddAzureEventHubs("event-hubs"); +builder.AddAzureEventHubs("event-hubs").AddHub("messages"); builder.AddAzureKeyVault("key-vault"); builder.AddAzureLogAnalyticsWorkspace("log-analytics-workspace"); builder.AddAzureOpenAI("openai"); diff --git a/docs/snippets/azure/AppHost/aspire-manifest.json b/docs/snippets/azure/AppHost/aspire-manifest.json index f8f69e01ab..618dc12c50 100644 --- a/docs/snippets/azure/AppHost/aspire-manifest.json +++ b/docs/snippets/azure/AppHost/aspire-manifest.json @@ -50,6 +50,10 @@ "principalId": "" } }, + "messages": { + "type": "value.v0", + "connectionString": "Endpoint={event-hubs.outputs.eventHubsEndpoint};EntityPath=messages" + }, "key-vault": { "type": "azure.bicep.v0", "connectionString": "{key-vault.outputs.vaultUri}", diff --git a/docs/snippets/azure/AppHost/event-hubs.module.bicep b/docs/snippets/azure/AppHost/event-hubs.module.bicep index 17ef915c2d..605bce42eb 100644 --- a/docs/snippets/azure/AppHost/event-hubs.module.bicep +++ b/docs/snippets/azure/AppHost/event-hubs.module.bicep @@ -28,4 +28,9 @@ resource event_hubs_AzureEventHubsDataOwner 'Microsoft.Authorization/roleAssignm scope: event_hubs } +resource messages 'Microsoft.EventHub/namespaces/eventhubs@2024-01-01' = { + name: 'messages' + parent: event_hubs +} + output eventHubsEndpoint string = event_hubs.properties.serviceBusEndpoint \ No newline at end of file