【发布时间】:2020-08-25 19:08:09
【问题描述】:
当我在 local.settings.json 中有一个有效的 AzureWebJobsServiceBus 时,我有一个 .netcore Azure Functions 项目在 Visual Studio 2019 中运行良好,但如果它缺失或为空,则无法编译。我正在使用 AD 向服务总线验证我的功能,而不是通过连接字符串。 AzureWebJobsServiceBus 在我的项目中的任何地方都没有使用。 这是我的 project.cs
我使用 Azure.Identity 包并按照this post 使用我的凭据登录到 Azure,这是我正在运行的函数:
[FunctionName("ProcessNewMessage")]
public async Task ProcessPaymentMessage([ServiceBusTrigger("topic", "subscription")] Message message, ILogger log) {
var tokenProvider = TokenProvider.CreateManagedIdentityTokenProvider();
QueueClient queueClient = new QueueClient($"sb://{Environment.GetEnvironmentVariable("ServiceBusEndPoint")}", Environment.GetEnvironmentVariable("GenericAuditQueueName"), tokenProvider);
await queueClient.SendAsync(message);
}
在使用 AD 进行身份验证之前,我使用的是连接字符串,这也可以,但建议使用 AD。
总而言之,当提供了连接字符串但我的代码未使用时,我的 Azure 函数可与服务总线触发器一起使用。如何在没有连接字符串的情况下使我的函数与 AD 一起工作?
非常感谢
【问题讨论】:
标签: azure-active-directory azure-functions azureservicebus