Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions docs/database/includes/cosmos-app-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<AzureCosmosDBResource>` to the <xref:Aspire.Hosting.AzureCosmosExtensions.AddDatabase*> API:
To add an Azure Cosmos DB database resource, chain a call on an `IResourceBuilder<AzureCosmosDBResource>` to the <xref:Aspire.Hosting.AzureCosmosExtensions.AddCosmosDatabase*> 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

Expand Down
34 changes: 21 additions & 13 deletions docs/messaging/azure-event-hubs-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <xref:Aspire.Hosting.Azure.AzureEventHubsResource> to your app host project, call the <xref:Aspire.Hosting.AzureEventHubsExtensions.AddAzureEventHubs*> method providing a name, and then chain a call to <xref:Aspire.Hosting.AzureEventHubsExtensions.AddHub*>:
To add an <xref:Aspire.Hosting.Azure.AzureEventHubsResource> to your app host project, call the <xref:Aspire.Hosting.AzureEventHubsExtensions.AddAzureEventHubs*> method providing a name, and then call <xref:Aspire.Hosting.AzureEventHubsExtensions.AddHub*>:

```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<Projects.ExampleService>()
.WithReference(eventHubs);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -139,16 +140,17 @@ To add a consumer group, chain a call on an `IResourceBuilder<AzureEventHubsReso
```csharp
var builder = DistributedApplication.CreateBuilder(args);

var eventHubs = builder.AddAzureEventHubs("event-hubs")
.AddConsumerGroup("messages");
var eventHubs = builder.AddAzureEventHubs("event-hubs");
var messages = eventHubs.AddHub("messages");
messages.AddConsumerGroup("messagesConsumer");

builder.AddProject<Projects.ExampleService>()
.WithReference(eventHubs);

// 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

Expand All @@ -160,9 +162,10 @@ To run the Event Hubs resource as an emulator, call the <xref:Aspire.Hosting.Azu
var builder = DistributedApplication.CreateBuilder(args);

var eventHubs = builder.AddAzureEventHubs("event-hubs")
.AddHub("messages")
.RunAsEmulator();

eventHubs.AddHub("messages");

var exampleProject = builder.AddProject<Projects.ExampleProject>()
.WithReference(eventHubs);

Expand All @@ -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<Projects.ExampleService>()
.WithReference(eventHubs);

Expand All @@ -215,12 +219,13 @@ To add a data volume to the Event Hubs emulator resource, call the <xref:Aspire.
var builder = DistributedApplication.CreateBuilder(args);

var eventHubs = builder.AddAzureEventHubs("event-hubs")
.AddHub("messages")
.RunAsEmulator(emulator =>
{
emulator.WithDataVolume();
});

eventHubs.AddHub("messages");

builder.AddProject<Projects.ExampleService>()
.WithReference(eventHubs);

Expand All @@ -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<Projects.ExampleService>()
.WithReference(eventHubs);

Expand All @@ -263,12 +269,13 @@ To provide a custom JSON configuration file, call the <xref:Aspire.Hosting.Azure
var builder = DistributedApplication.CreateBuilder(args);

var eventHubs = builder.AddAzureEventHubs("event-hubs")
.AddHub("messages")
.RunAsEmulator(emulator =>
{
emulator.WithConfigurationFile("./messaging/custom-config.json");
});

eventHubs.AddHub("messages");

builder.AddProject<Projects.ExampleService>()
.WithReference(eventHubs);

Expand All @@ -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(
Expand All @@ -295,6 +301,8 @@ var eventHubs = builder.AddAzureEventHubs("event-hubs")
});
});

eventHubs.AddHub("messages");

builder.AddProject<Projects.ExampleService>()
.WithReference(eventHubs);

Expand Down
70 changes: 34 additions & 36 deletions docs/messaging/azure-service-bus-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AzureServiceBusResource>` to the <xref:Aspire.Hosting.AzureServiceBusExtensions.WithQueue*> API:
To add an Azure Service Bus queue, call the <xref:Aspire.Hosting.AzureServiceBusExtensions.AddServiceBusQueue*> method on the `IResourceBuilder<AzureServiceBusResource>`:

```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 `<IResourceBuilder<AzureServiceBusResource>>` to the <xref:Aspire.Hosting.AzureServiceBusExtensions.WithTopic*> API:
To add an Azure Service Bus topic, call the <xref:Aspire.Hosting.AzureServiceBusExtensions.AddServiceBusTopic*> method on the `IResourceBuilder<AzureServiceBusResource>`:

```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 <xref:Aspire.Hosting.AzureServiceBusExtensions.WithTopic*> API:
To add a subscription for the topic, call the <xref:Aspire.Hosting.AzureServiceBusExtensions.AddServiceBusSubscription*> method on the `IResourceBuilder<AzureServiceBusTopicResource>` and configure it using the <xref:Aspire.Hosting.AzureServiceBusExtensions.WithProperties*> 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).

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/azure/AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions docs/snippets/azure/AppHost/aspire-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
5 changes: 5 additions & 0 deletions docs/snippets/azure/AppHost/event-hubs.module.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading