如何解决带QueueTrigger的Azure功能:是否可以仅配置存储帐户网址并使用托管身份访问队列?
我已经定义了此功能:
[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函数中的托管身份(具有 Processor 权限)来读取/触发在邮件上。
解决方法
我认为您的要求是不可能的。
连接到存储的基础代码已封装在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。
下载source code of webjobs package,并检查queuetrigger的源代码,您会发现该源代码未实现所需的代码。您无法告诉该功能您要使用MSI,并且它无法为您提供使用此功能的任何方式。
简而言之,源代码无法实现您的想法。除非您修改源代码的基础实现,重新编译并导入程序包,否则是不可能的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。