我有一个带有多个队列触发函数的 Azure webjob。 SDK 文档位于https://learn.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-storage-queues-how-to#config定义了MaxDequeueCount
属性为:
队列消息发送到队列之前的最大重试次数
毒物队列(默认为 5)。
但我没有看到这种行为。在我的网络作业中,我有:
JobHostConfiguration config = new JobHostConfiguration();
config.Queues.MaxDequeueCount = 1;
JobHost host = new JobHost(config);
host.RunAndBlock();
然后我有一个队列触发的函数,在其中抛出异常:
public void ProcessQueueMessage([QueueTrigger("azurewejobtestingqueue")] string item, TextWriter logger)
{
if ( item == "exception" )
{
throw new Exception();
}
}
查看 webjobs 仪表板,我发现 SDK 进行了 5 次尝试(如上所述,5 次是默认值):
![Webjob failures shown on webjobs dashboard](https://i.stack.imgur.com/FOkAv.png)
在第五次尝试后,该消息将被移至有害队列。我预计会看到 1 次重试(或没有重试?),而不是 5 次。
更新:为 Web 应用程序启用详细日志记录,并选择将这些日志保存到 Azure blob 容器。发现一些与我的问题相关的日志位于azure-jobs-host-archive
容器。下面的示例显示了出队计数为 96 的项目:
{
"Type": "FunctionCompleted",
"EndTime": "2017-02-22T00:07:40.8133081+00:00",
"Failure": {
"ExceptionType": "Microsoft.Azure.WebJobs.Host.FunctionInvocationException",
"ExceptionDetails": "Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: ItemProcessor.ProcessQueueMessage ---> MyApp.Exceptions.MySpecialAppExceptionType: Exception of type 'MyApp.Exceptions.MySpecialAppExceptionType' was thrown.
},
"ParameterLogs": {},
"FunctionInstanceId": "1ffac7b0-1290-4343-8ee1-2af0d39ae2c9",
"Function": {
"Id": "MyApp.Processors.ItemProcessor.ProcessQueueMessage",
"FullName": "MyApp.Processors.ItemProcessor.ProcessQueueMessage",
"ShortName": "ItemProcessor.ProcessQueueMessage",
"Parameters": [
{
"Type": "QueueTrigger",
"AccountName": "MyStorageAccount",
"QueueName": "stuff-processor",
"Name": "sourceFeedItemQueueItem"
},
{
"Type": "BindingData",
"Name": "dequeueCount"
},
{
"Type": "ParameterDescriptor",
"Name": "logger"
}
]
},
"Arguments": {
"sourceFeedItemQueueItem": "{\"SourceFeedUpdateID\":437530,\"PodcastFeedID\":\"2d48D2sf2\"}",
"dequeueCount": "96",
"logger": null
},
"Reason": "AutomaticTrigger",
"ReasonDetails": "New queue message detected on 'stuff-processor'.",
"StartTime": "2017-02-22T00:07:40.6017341+00:00",
"OutputBlob": {
"ContainerName": "azure-webjobs-hosts",
"BlobName": "output-logs/1ffd3c7b012c043438ed12af0d39ae2c9.txt"
},
"ParameterLogBlob": {
"ContainerName": "azure-webjobs-hosts",
"BlobName": "output-logs/1cf2c1b012sa0d3438ee12daf0d39ae2c9.params.txt"
},
"LogLevel": "Info",
"HostInstanceId": "d1825bdb-d92a-4657-81a4-36253e01ea5e",
"HostDisplayName": "ItemProcessor",
"SharedQueueName": "azure-webjobs-host-490daea03c70316f8aa2509438afe8ef",
"InstanceQueueName": "azure-webjobs-host-d18252sdbd92a4657d1a436253e01ea5e",
"Heartbeat": {
"SharedContainerName": "azure-webjobs-hosts",
"SharedDirectoryName": "heartbeats/490baea03cfdfd0416f8aa25aqr438afe8ef",
"InstanceBlobName": "zd1825bdbdsdgga465781a436q53e01ea5e",
"ExpirationInSeconds": 45
},
"WebJobRunIdentifier": {
"WebSiteName": "myappengine",
"JobType": "Continuous",
"JobName": "ItemProcessor",
"RunId": ""
}
}
我进一步寻找的是日志,它将向我显示特定队列项目的详细信息,其中处理成功(因此从队列中删除)或由于异常而失败并被放置在毒物队列中。到目前为止,我还没有找到任何显示该详细信息的日志。上面输出中引用的日志文件不包含此类数据。
更新2:看了我的毒药队列的状态,看起来它可能是确凿无疑的,但我太密集了,无法将2和2放在一起。查看下面队列的屏幕截图,您可以看到带有 ID 的消息(左列)431210
在那里很多次。它出现多次的事实告诉我原始队列中的消息失败了不恰当地.
![Poison queue](https://i.stack.imgur.com/amAVk.png)