gpt4 book ai didi

c# - 连接字符串有时在 ServiceBusTrigger 中不可用

转载 作者:太空狗 更新时间:2023-10-29 17:50:16 25 4
gpt4 key购买 nike

我有一个带有服务总线触发器的 Azure 函数:

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

在 99.9% 的调用中,触发器成功解析为 Azure 服务总线上的订阅。但有时,我会在日志中看到以下错误:

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()

似乎服务总线触发器无法从设置中解析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);
}
}

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

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

最佳答案

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

关于c# - 连接字符串有时在 ServiceBusTrigger 中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54644958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com