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
7 changes: 7 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<PackageVersion Include="Azure.Storage.Blobs" Version="12.17.0" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.15.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.0" />

<!-- Azure Management SDK for .NET dependencies -->
<PackageVersion Include="Azure.ResourceManager.KeyVault" Version="1.2.0-beta.2" />
<PackageVersion Include="Azure.ResourceManager.ServiceBus" Version="1.1.0-beta.3" />
<PackageVersion Include="Azure.ResourceManager.Storage" Version="1.1.1" />
<PackageVersion Include="Azure.ResourceManager.Authorization" Version="1.1.0-beta.1" />

<!-- ASP.NET Core dependencies -->
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(AspNetCoreVersion)" />
Expand Down
4 changes: 3 additions & 1 deletion samples/DevHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureProvisioning();

var grafana = builder.AddContainer("grafana", "grafana/grafana")
.WithServiceBinding(containerPort: 3000, name: "grafana-http", scheme: "http");

Expand All @@ -18,7 +20,7 @@
.WithReplicas(2)
.WithSqlServer(sql, "master");

var serviceBus = builder.AddAzureServiceBus("messaging");
var serviceBus = builder.AddAzureServiceBus("messaging", "orders");

var basket = builder.AddProject<Projects.BasketService>()
.WithRedis(redis)
Expand Down
24 changes: 14 additions & 10 deletions samples/OrderProcessor/OrderProcessingWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}

const string configKeyName = "Aspire:Azure:Messaging:ServiceBus:OrderQueueName";
string queueName = _config[configKeyName] ?? throw new InvalidOperationException($"Queue name not found. Please add a valid name for configuration key '{configKeyName}'.");
string queueName = _config[configKeyName] ?? "orders";

_messageProcessor = _client.CreateProcessor(queueName);
_messageProcessor.ProcessMessageAsync += ProcessMessageAsync;
Expand All @@ -58,20 +58,24 @@ private Task ProcessMessageAsync(ProcessMessageEventArgs args)
_logger.LogInformation($"Processing Order at: {DateTime.UtcNow}");

var message = args.Message;
_logger.LogDebug($"""
MessageId:{message.MessageId}
MessageBody:{message.Body}
""");

if (_logger.Equals(LogLevel.Debug))
{
_logger.LogDebug("""
MessageId:{MessageId}
MessageBody:{Body}
""", message.MessageId, message.Body);
}
var order = message.Body.ToObjectFromJson<Order>();

activity?.AddTag("order-id", order.Id);
activity?.AddTag("product-count", order.Items.Count);

_logger.LogCritical($"""
OrderId:{order.Id}
BuyerId:{order.BuyerId}
ProductCount:{order.Items.Count}
""");
_logger.LogInformation("""
OrderId:{Id}
BuyerId:{BuyerId}
ProductCount:{Count}
""", order.Id, order.BuyerId, order.Items.Count);

return Task.CompletedTask;
}
Expand Down
2 changes: 2 additions & 0 deletions samples/OrderProcessor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var builder = Host.CreateApplicationBuilder(args);

builder.AddServiceDefaults();

// When running for Development, don't fail at startup if the developer hasn't configured ServiceBus yet.
if (!builder.Environment.IsDevelopment() || builder.Configuration[AspireServiceBusExtensions.DefaultNamespaceConfigKey] is not null)
{
Expand Down
7 changes: 6 additions & 1 deletion src/Aspire.Hosting.Azure/Aspire.Hosting.Azure.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
Expand All @@ -7,6 +7,11 @@

<ItemGroup>
<ProjectReference Include="..\Aspire.Hosting\Aspire.Hosting.csproj" />
<PackageReference Include="Azure.ResourceManager.KeyVault" />
<PackageReference Include="Azure.ResourceManager.ServiceBus" />
<PackageReference Include="Azure.ResourceManager.Storage" />
<PackageReference Include="Azure.ResourceManager.Authorization" />
<PackageReference Include="Azure.Identity" />
</ItemGroup>

</Project>
86 changes: 86 additions & 0 deletions src/Aspire.Hosting.Azure/AzureComponentExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;

namespace Aspire.Hosting.Azure;

public static class AzureComponentExtensions
{
public static IDistributedApplicationBuilder AddAzureProvisioning(this IDistributedApplicationBuilder builder)
{
builder.Services.AddLifecycleHook<AzureProvisioner>();
return builder;
}

public static IDistributedApplicationComponentBuilder<AzureKeyVaultComponent> AddAzureKeyVault(this IDistributedApplicationBuilder builder, string name)
{
var component = new AzureKeyVaultComponent();
return builder.AddComponent(name, component);
}

public static IDistributedApplicationComponentBuilder<T> WithAddAzureKeyVault<T>(this IDistributedApplicationComponentBuilder<T> builder, IDistributedApplicationComponentBuilder<AzureKeyVaultComponent> keyvalut)
where T : IDistributedApplicationComponentWithEnvironment
{
return builder.WithEnvironment((env) =>
{
var vaultName = keyvalut.Component.VaultName ?? builder.ApplicationBuilder.Configuration["Aspire:Azure:Security:KeyVault:VaultName"];

if (vaultName is not null)
{
env[$"Aspire__Azure__Security__KeyVault__VaultUri"] = $"https://{vaultName}.vault.azure.net/";
}
});
}

public static IDistributedApplicationComponentBuilder<AzureServiceBusComponent> AddAzureServiceBus(this IDistributedApplicationBuilder builder, string name, params string[] queueNames)
{
var component = new AzureServiceBusComponent
{
QueueNames = queueNames
};

return builder.AddComponent(name, component);
}

public static IDistributedApplicationComponentBuilder<T> WithAzureServiceBus<T>(this IDistributedApplicationComponentBuilder<T> builder, IDistributedApplicationComponentBuilder<AzureServiceBusComponent> serviceBus)
where T : IDistributedApplicationComponentWithEnvironment
{
return builder.WithEnvironment((env) =>
{
var sbNamespace = serviceBus.Component.ServiceBusNamespace ?? builder.ApplicationBuilder.Configuration["Aspire:Azure:Messaging:ServiceBus:Namespace"];

if (sbNamespace is not null)
{
env[$"Aspire__Azure__Messaging__ServiceBus__Namespace"] = $"{sbNamespace}.servicebus.windows.net";
}
});
}

public static IDistributedApplicationComponentBuilder<AzureStorageComponent> AddAzureStorage(this IDistributedApplicationBuilder builder, string name)
{
var component = new AzureStorageComponent();
return builder.AddComponent(name, component);
}

public static IDistributedApplicationComponentBuilder<T> WithAzureStorage<T>(this IDistributedApplicationComponentBuilder<T> builder, IDistributedApplicationComponentBuilder<AzureStorageComponent> storage)
where T : IDistributedApplicationComponentWithEnvironment
{
return builder.WithEnvironment((env) =>
{
// We don't support connection strings yet
//storage.Component.TryGetName(out var name);
//env[$"ConnectionStrings__{name}"] = storage.Component.ConnectionString!;

var accountName = storage.Component.AccountName ?? builder.ApplicationBuilder.Configuration["Aspire:Azure:Storage:AccountName"];

if (accountName is not null)
{
env[$"Aspire__Azure__Data__Tables__ServiceUri"] = $"https://{accountName}.table.core.windows.net/";
env[$"Aspire__Azure__Storage__Blobs__ServiceUri"] = $"https://{accountName}.blob.core.windows.net/";
env[$"Aspire__Azure__Storage__Queues__ServiceUri"] = $"https://{accountName}.queue.core.windows.net/";
}
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace Aspire.Hosting.Azure;

public class ServiceBusComponent : IDistributedApplicationComponent
public class AzureKeyVaultComponent : IAzureComponent
{
public ComponentMetadataCollection Annotations { get; } = new();

public string? VaultName { get; set; }
}
Loading