ServiceBusTrigger中有时不提供连接字符串

Tho*_*dal 9 c# azureservicebus azure-functions

我有一个带有服务总线触发器的Azure功能:

public static async Task Run([ServiceBusTrigger(
    "%inputTopicName%",
    "%subscriptionName%",
    AccessRights.Manage,
    Connection = "connection")]string mySbMsg)
Run Code Online (Sandbox Code Playgroud)

在99.9%的调用中,触发器成功解析为Azure Service Bus上的订阅.但有时,我在日志中看到以下错误:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: UptimeChecker ---> System.ArgumentException: The argument connectionString is null or white space.
Parameter name: connectionString
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.FunctionInvocationFilterInvoker.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__16.MoveNext()
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext()
Run Code Online (Sandbox Code Playgroud)

似乎服务总线触发器无法connection从设置中解析变量.

我试图在我的函数中添加一个调试过滤器,以便了解发生了什么:

public class DebuggingFilter : FunctionInvocationFilterAttribute
{
    public override Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken)
    {
        executingContext.Properties.Add("connection", ConfigurationManager.AppSettings["connection"]);
        executingContext.Properties.Add("inputTopicName", ConfigurationManager.AppSettings["inputTopicName"]);
        executingContext.Properties.Add("subscriptionName", ConfigurationManager.AppSettings["subscriptionName"]);
        return base.OnExecutingAsync(executingContext, cancellationToken);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的函数中记录错误时,添加到的属性FunctionExecutionContext会自动添加到日志消息中.这里奇怪的是,在Azure Functions抛出此异常的情况下,属性值将被解析并显示在日志消息中.

可能是什么原因造成的?我在解决Azure功能设置时遇到了多个问题,所以这可能是一个普遍问题?

Tho*_*dal 5

我没有这个问题的最终答案,但我确实想与其他遇到相同问题的人分享一些细节。该问题似乎仅与基于v1消耗的功能无关。将我的功能升级到Azure Functions v2并利用那里可用的新配置系统后,我不再遇到上述问题。由于v1不再是当前版本,因此当v2似乎可以正常工作时,我不想花更多的时间对此进行调试。