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

标签 c# azure-functions azureservicebus

我有一个带有服务总线触发器的 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/

相关文章:

Azure Functions 在与 Azure Cosmos DB 或 SQL 数据库结合进行负载测试时失败

azure - Azure.Messaging.ServiceBus 命名空间中是否有 CreateSharedAccessSignatureTokenProvider 的替代品?

azure - 如何查看最近发送到服务总线队列中的消息?

c# - 为什么 IEnumerable<T> 派生自 IEnumerable?

c# - keydown事件取消其他c#

python - Azure Functions Python 连接到 Azure SQL DB

java - 如何使用 Java 将错误消息移动到 Azure 死信队列?

c# - 我可以从 Visual Studio 中设置 LARGEADDRESSAWARE 吗?

c# - 将对象传递给 UITypeEditor

c# - 在 Azure Function 中访问 VSTS 构建服务器版本