The maximum number of retries before a queue message is sent to a
poison queue (default is 5).
但我没有看到这种行为.在我的webjob中我得到了:
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是默认值,如上所述):
在第5次尝试之后,消息被移动到毒药队列.我希望看到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的消息.多次出现这一事实告诉我原始队列中的消息未正确失败.
解决方法
贡献者asifferman在issue #985上共享了一个code snippet in a comment post.这似乎解决了这个问题(它对我来说非常合适).
For those (like me) who cannot wait the next release to get the
WebJobs SDK to work with the latest releases of Azure Storage,and
based on the explanations of @brettsam,you can simply write a custom
CustomQueueProcessorFactory to create a new CloudQueueMessage in
CopyMessageToPoisonQueueAsync.
namespace ConsoleApplication1 { using Microsoft.Azure.WebJobs.Host.Queues; using Microsoft.WindowsAzure.Storage.Queue; using System.Threading; using System.Threading.Tasks; public class CustomQueueProcessorFactory : IQueueProcessorFactory { public QueueProcessor Create(QueueProcessorFactoryContext context) { return new CustomQueueProcessor(context); } private class CustomQueueProcessor : QueueProcessor { public CustomQueueProcessor(QueueProcessorFactoryContext context) : base(context) { } protected override Task CopyMessageToPoisonQueueAsync(CloudQueueMessage message,CloudQueue poisonQueue,CancellationToken cancellationToken) { var newMessage = new CloudQueueMessage(message.Id,message.PopReceipt); newMessage.SetMessageContent(message.AsBytes); return base.CopyMessageToPoisonQueueAsync(newMessage,poisonQueue,cancellationToken); } } } }
Then in your Main,you just have to set the custom queue processor
factory in the job host configuration:
var config = new JobHostConfiguration(); config.Queues.QueueProcessorFactory = new CustomQueueProcessorFactory();
I could get it work with WindowsAzure.Storage 8.1.1 and Microsoft.Azure.WebJobs 2.0.0. Hope that helps!