Browse Source

Add Azure.Identity support to AzureServiceBus client config.

pull/24152/head
maliming 3 months ago
parent
commit
a67491ab75
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 5
      Directory.Packages.props
  2. 10
      docs/en/framework/infrastructure/event-bus/distributed/azure.md
  3. 1
      framework/src/Volo.Abp.AzureServiceBus/Volo.Abp.AzureServiceBus.csproj
  4. 7
      framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ClientConfig.cs
  5. 25
      framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ConnectionPool.cs

5
Directory.Packages.props

@ -17,6 +17,7 @@
<PackageVersion Include="AWSSDK.S3" Version="4.0.7.2" />
<PackageVersion Include="AWSSDK.SecurityToken" Version="4.0.2.2" />
<PackageVersion Include="BunnyCDN.Net.Storage" Version="1.0.4" />
<PackageVersion Include="Azure.Identity" Version="1.14.2" />
<PackageVersion Include="Azure.Messaging.ServiceBus" Version="7.20.1" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.25.0" />
<PackageVersion Include="Blazorise" Version="1.8.5" />
@ -88,7 +89,6 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.61.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.61.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Hybrid" Version="9.9.0" />
@ -190,5 +190,6 @@
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2" />
<PackageVersion Include="Fody" Version="6.9.3" />
<PackageVersion Include="System.Management" Version="10.0.0"/>
<PackageVersion Include="System.Management" Version="10.0.0" />
</ItemGroup>
</Project>
</Project>

10
docs/en/framework/infrastructure/event-bus/distributed/azure.md

@ -137,4 +137,14 @@ Configure<AbpAzureServiceBusOptions>(options =>
});
````
Use `TokenCredential` instead of `ConnectionString` if you want to use custom credential.
````csharp
Configure<AbpAzureServiceBusOptions>(options =>
{
options.Connections.Default.FullyQualifiedNamespace = "sb-my-app.servicebus.windows.net";
options.Connections.Default.TokenCredential = new DefaultAzureCredential();
});
````
Using these options classes can be combined with the `appsettings.json` way. Configuring an option property in the code overrides the value in the configuration file.

1
framework/src/Volo.Abp.AzureServiceBus/Volo.Abp.AzureServiceBus.csproj

@ -17,6 +17,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Messaging.ServiceBus" />
<ProjectReference Include="..\Volo.Abp.Json\Volo.Abp.Json.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />

7
framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ClientConfig.cs

@ -1,3 +1,4 @@
using Azure.Core;
using Azure.Messaging.ServiceBus;
using Azure.Messaging.ServiceBus.Administration;
@ -5,7 +6,7 @@ namespace Volo.Abp.AzureServiceBus;
public class ClientConfig
{
public string ConnectionString { get; set; } = default!;
public string? ConnectionString { get; set; }
public ServiceBusAdministrationClientOptions Admin { get; set; } = new();
@ -15,4 +16,8 @@ public class ClientConfig
{
AutoCompleteMessages = false
};
public TokenCredential? TokenCredential { get; set; }
public string? FullyQualifiedNamespace { get; set; }
}

25
framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ConnectionPool.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.Messaging.ServiceBus;
using Azure.Messaging.ServiceBus.Administration;
using Microsoft.Extensions.Logging;
@ -35,7 +36,17 @@ public class ConnectionPool : IConnectionPool, ISingletonDependency
connectionName, new Lazy<ServiceBusClient>(() =>
{
var config = _options.Connections.GetOrDefault(connectionName);
return new ServiceBusClient(config.ConnectionString, config.Client);
if (!config.ConnectionString.IsNullOrWhiteSpace())
{
return new ServiceBusClient(config.ConnectionString, config.Client);
}
if (!config.FullyQualifiedNamespace.IsNullOrWhiteSpace() && config.TokenCredential != null)
{
return new ServiceBusClient(config.FullyQualifiedNamespace, config.TokenCredential, config.Client);
}
throw new InvalidOperationException($"{connectionName} does not have a valid Service Bus connection configuration.");
})
).Value;
}
@ -47,7 +58,17 @@ public class ConnectionPool : IConnectionPool, ISingletonDependency
connectionName, new Lazy<ServiceBusAdministrationClient>(() =>
{
var config = _options.Connections.GetOrDefault(connectionName);
return new ServiceBusAdministrationClient(config.ConnectionString, config.Admin);
if (!config.ConnectionString.IsNullOrWhiteSpace())
{
return new ServiceBusAdministrationClient(config.ConnectionString, config.Admin);
}
if (!config.FullyQualifiedNamespace.IsNullOrWhiteSpace() && config.TokenCredential != null)
{
return new ServiceBusAdministrationClient(config.FullyQualifiedNamespace, config.TokenCredential, config.Admin);
}
throw new InvalidOperationException($"{connectionName} does not have a valid Service Bus connection configuration.");
})
).Value;
}

Loading…
Cancel
Save