连接字符串有时在ServiceBusTrigger

时间:2019-02-12 07:36:51

标签: c# azure-functions azureservicebus

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

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

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

服务总线触发器似乎无法通过设置解析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解析设置时遇到了多个问题,也许这是一个普遍问题?

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:3)

据此: 您应该将最新版本2.3.0用于nuget Microsoft.Azure.WebJobs.ServiceBus-版本2.3.0

我还将通过对连接进行硬编码来检查在连接计划中运行是否存在问题,从而在消耗计划中运行时检查是否存在问题。并在应用服务计划上对其进行测试。