【问题标题】:Using Singleton attribute with ServiceBusTrigger in WebJobs SDK在 WebJobs SDK 中使用带有 ServiceBusTrigger 的 Singleton 属性
【发布时间】:2015-09-28 14:25:37
【问题描述】:

我正在使用 Microsoft.Azure.WebJobsMicrosoft.Azure.WebJobs.ServiceBus 包来捕获 ServiceBus 主题事件。

功能代码如下-

public class Functions
{
    [Singleton]
    public static void Event4Processor(
      [ServiceBusTrigger("MyTopic", "MySubscription", AccessRights.Listen)] BrokeredMessage message,
      TextWriter log)
    {
        log.WriteLine(message);
    }
}

但是,我收到了这个错误

{
  "Type": "FunctionCompleted",
  "EndTime": "2015-09-28T13:53:36.6540039+00:00",
  "Failure": {
    "ExceptionType": "System.ArgumentNullException",
    "ExceptionDetails": "System.ArgumentNullException: Value cannot be null.\r\nParameter name: bindingData\r\n   at Microsoft.Azure.WebJobs.Host.Bindings.BindingDataPathHelper.ConvertParameters(IReadOnlyDictionary`2 bindingData)\r\n   at Microsoft.Azure.WebJobs.Host.SingletonManager.GetBoundScope(String scope, IReadOnlyDictionary`2 bindingData)\r\n   at Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.<BindCoreAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.<BindAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLogMessageAsync>d__c.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__1.MoveNext()"
  },
  "ParameterLogs": {},
  "FunctionInstanceId": "a1dcf0a9-113f-4c7e-b136-fb8d8b7ee4aa",
  "Function": {
    "Id": "WebJobServiceBus.Functions.Event4Processor",
    "FullName": "WebJobServiceBus.Functions.Event4Processor",
    "ShortName": "Functions.Event4Processor",
    "Parameters": [
      {
        "NamespaceName": "my-ns",
        "TopicName": "myevents",
        "SubscriptionName": "mysubscription",
        "Name": "message",
        "DisplayHints": {
          "Description": "dequeue from 'mytopic/Subscriptions/mysubscription'",
          "Prompt": "Enter the queue message body"
        }
      },
      {
        "Type": "ParameterDescriptor",
        "Name": "log"
      }
    ]
  },
  "Reason": "AutomaticTrigger",
  "ReasonDetails": "New ServiceBus message detected on 'MyTopic/Subscriptions/MySubscription'.",
  "StartTime": "2015-09-28T13:53:35.6639049+00:00",
  "HostInstanceId": "ad1f5b26-ddec-4326-9cfb-df585065e773",
  "HostDisplayName": "WebJobServiceBus",
  "SharedQueueName": "azure-webjobs-host-ef6959df3bc9431680c944c6ca5b1eff",
  "InstanceQueueName": "azure-webjobs-host-ad1f5b26ddec43269cfbdf585065e773",
  "Heartbeat": {
    "SharedContainerName": "azure-webjobs-hosts",
    "SharedDirectoryName": "heartbeats/ef6959df3bc9431680c944c6ca5b1eff",
    "InstanceBlobName": "ad1f5b26ddec43269cfbdf585065e773",
    "ExpirationInSeconds": 45
  }
}

如果我删除 Singleton 属性,一切正常!

我尝试过类似的选项 -

[Singleton(@"{CorrelationId}")]

但是,它没有帮助。

有什么问题(和解决方法)?

【问题讨论】:

    标签: c# azureservicebus azure-webjobssdk


    【解决方案1】:

    我相信我看到了一个我们明天可以修复的错误。目前,您应该能够通过绑定到您自己的 POCO 类型而不是 BrokeredMessage 来解决此问题。你现在可以试试吗?

    当我准备好后,我会回复这个帖子并提供一个更新包的链接。

    谢谢。

    【讨论】:

    • 此问题现已修复。您可以从 MyGet "Nightlies" 提要中获取带有修复程序的更新包,此处的说明:github.com/Azure/azure-webjobs-sdk/wiki/%22Nightly%22-Builds
    • 感谢 mathewc。这是否仅包括 SIngleTon 修复或其他更改?我还观察到网络作业(部署了 Windows 服务)在一段时间后停止响应/收听。如果您重新启动该服务,它会再次接收错过的消息。我怀疑这可能是由于瞬态网络丢失(或另一个错误!)。有什么办法可以处理吗?
    • 我不明白您的部署方案 - 您将 WebJob 部署为“Windows 服务”是什么意思?
    • WebJob 控制台应用程序正在转换为 Windows 服务(使用 ToShelf)。 Webjob 调用第三方 API。这个第三方 API 提供商需要静态 IP 来将我们的网络作业列入白名单作为可信来源。在 WebApp 中托管 WebJob 会生成一个动态 IP,因此我们必须将其作为 Windows 服务托管在 VM 上。 VM 将始终具有静态 IP。 HTH。
    • 在 Azure Web 应用程序中运行时,WebJobs 基础结构负责确保您的作业保持运行(当您启用 AlwaysOn 时)。例如,如果您的作业因错误而失败,基础设施将重新启动它并使其保持活动状态。由于您在该基础架构之外运行,因此由您来实现“保持活动”行为。
    猜你喜欢
    • 2015-04-02
    • 2019-05-16
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多