【问题标题】:Connection string is sometimes not available in ServiceBusTrigger连接字符串有时在 ServiceBusTrigger 中不可用
【发布时间】:2019-02-17 19:19:39
【问题描述】:

我有一个带有服务总线触发器的 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 设置时遇到了多个问题,所以这可能是一个普遍问题?

【问题讨论】:

  • 什么是 nuget 版本 * Microsoft.Azure.WebJobs.ServiceBus?你检查过 Kudu Logs YOURFUNCTION.scm.azurewebsites.net/DebugConsole D:\home\LogFiles\Application\Functions\function\YOURFUNCTION
  • 该软件包的版本为 2.2.0。
  • 您是否尝试更新到最新的 nuget?
  • 你在本地测试吗?
  • 本地这总是有效的。该问题仅出现在 Azure 上。

标签: c# azure-functions azureservicebus


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    据此: 您应该为 nuget Microsoft.Azure.WebJobs.ServiceBus -Version 2.3.0 使用最新版本 2.3.0

    我还会通过硬编码连接来检查在消费计划中运行时是否存在问题,以查看读取连接配置是否存在问题。否则在应用服务计划上进行测试。

    【讨论】:

    • 据我了解,第 3 版适用于 Functions v2。
    猜你喜欢
    • 2021-01-26
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 2019-09-17
    相关资源
    最近更新 更多