带有QueueTrigger的Azure函数:是否可以仅配置存储帐户Url并使用托管身份访问队列



我定义了这个函数:

[FunctionName("My_QueueTrigger")]
public Task RunAsync([QueueTrigger("my-queue-name", Connection = "AzureWebJobsStorage")] string text)
{
// code here...
}

AzureWebJobsStorage(在Azure上(包含以下内容:"DefaultEndpointsProtocol=https;AccountName=my-storage-account;AccountKey=mykey;EndpointSuffix=core.windows.net"

(注意,对于本地开发,该值为"UseDevelopmentStorage=true"。(

我的问题是,也可以像"https://my-storage-account.queue.core.windows.net"一样在这里定义存储帐户名称,并使用Azure功能中的托管身份(具有处理器权限(来读取/触发消息。

我认为你的要求是不可能的。

连接到存储的底层代码已封装在WebJob包中,该包作为成员包包含在整个功能的扩展包中。您必须修改底层代码才能实现所需的功能。

检查queuetrigger属性的源代码:

using System;
using System.Diagnostics;
using Microsoft.Azure.WebJobs.Description;
namespace Microsoft.Azure.WebJobs
{
/// <summary>
/// Attribute used to bind a parameter to an Azure Queue message, causing the function to run when a
/// message is enqueued.
/// </summary>
/// <remarks>
/// The method parameter type can be one of the following:
/// <list type="bullet">
/// <item><description>CloudQueueMessage</description></item>
/// <item><description><see cref="string"/></description></item>
/// <item><description><see cref="T:byte[]"/></description></item>
/// <item><description>A user-defined type (serialized as JSON)</description></item>
/// </list>
/// </remarks>
[AttributeUsage(AttributeTargets.Parameter)]
[DebuggerDisplay("{QueueName,nq}")]
[ConnectionProvider(typeof(StorageAccountAttribute))]
[Binding]
public sealed class QueueTriggerAttribute : Attribute, IConnectionProvider
{
private readonly string _queueName;
/// <summary>Initializes a new instance of the <see cref="QueueTriggerAttribute"/> class.</summary>
/// <param name="queueName">The name of the queue to which to bind.</param>
public QueueTriggerAttribute(string queueName)
{
_queueName = queueName;
}
/// <summary>Gets the name of the queue to which to bind.</summary>
public string QueueName
{
get { return _queueName; }
}
/// <summary>
/// Gets or sets the app setting name that contains the Azure Storage connection string.
/// </summary>
public string Connection { get; set; }
}
}

你可以找到源代码,它告诉我们需要给出连接字符串,而不是存储url。

下载webjobs包的源代码,检查queuetrigger的源代码时,你会发现源代码没有实现你想要的。你不能告诉函数你想使用MSI,它也不会为你提供任何使用此功能的方法。

简而言之,源代码无法实现您的想法。除非修改源代码的底层实现,重新编译并导入包,否则这是不可能的。