我已经尝试实现自己的 QueueProcessorFactory ,它运行正常,除了一件我无法解决的问题。在我尝试了5次消息(默认)后,它会运行 CopyMessageToPoisonQueueAsync ,然后运行 DeleteMessageAsync 。
到目前为止一直很好,但10分钟后,该消息再次出现在队列中,并且出队计数为5,并且它也在毒性队列中,然后是相同的过程, CopyMessageToPoisonQueueAsync ,< em> DeleteMessageAsync ,posionqueue中的额外项目与已经复制的项目完全相同,10分钟后相同的程序但出列计数为6.我应该更改ExpirationTime并在删除时将其设置为现在,或者执行我想念别的什么?
这是我的代码:
class Program
{
static void Main()
{
var config = new JobHostConfiguration();
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(3);
config.Queues.QueueProcessorFactory = new CustomQueueProcessorFactory();
var host = new JobHost(config);
host.RunAndBlock();
}
}
public class CustomQueueProcessorFactory : IQueueProcessorFactory
{
public List<CustomQueueProcessor> CustomQueueProcessors = new List<CustomQueueProcessor>();
public QueueProcessor Create(QueueProcessorFactoryContext context)
{
CustomQueueProcessor processor = new CustomQueueProcessor(context);
CustomQueueProcessors.Add(processor);
return processor;
}
public class CustomQueueProcessor : QueueProcessor
{
public CustomQueueProcessor(QueueProcessorFactoryContext context)
: base(context)
{
}
public override Task<bool> BeginProcessingMessageAsync(CloudQueueMessage message, CancellationToken cancellationToken)
{
return base.BeginProcessingMessageAsync(message, cancellationToken);
}
public override Task CompleteProcessingMessageAsync(CloudQueueMessage message, FunctionResult result, CancellationToken cancellationToken)
{
return base.CompleteProcessingMessageAsync(message, result, cancellationToken);
}
protected override Task CopyMessageToPoisonQueueAsync(CloudQueueMessage message, CloudQueue poisonQueue, CancellationToken cancellationToken)
{
return base.CopyMessageToPoisonQueueAsync(message, poisonQueue, cancellationToken);
}
protected override Task DeleteMessageAsync(CloudQueueMessage message, CancellationToken cancellationToken)
{
return base.DeleteMessageAsync(message, cancellationToken);
}
protected override async Task ReleaseMessageAsync(CloudQueueMessage message, FunctionResult result, TimeSpan visibilityTimeout, CancellationToken cancellationToken)
{
visibilityTimeout = TimeSpan.FromSeconds(2);
await base.ReleaseMessageAsync(message, result, visibilityTimeout, cancellationToken);
}
}
}
如果我添加一些ConsoleWritelines,我得到这个输出:
因重复而开始省略 。 。
BeginProcessingMessageAsync消息:d3c88182-ff39-4f81-8c29-b4ce0b2062ad dequeue count:5日期:2017-06-26 13:33:42 执行'Functions.ProcessQueueMessage'(Reason ='在'01testqueue'上检测到新队列消息。',Id = 17405a55-6d28-48b2-a874-718c0b741f61) Test QueueProcessorFactory 执行函数时出现异常:Functions.ProcessQueueMessage Microsoft.Azure.WebJobs.Host.FunctionInvocationException:执行函数时出现异常:Functions.ProcessQueueMessage ---&gt; System.Exception:Derp! at WebJobTest1.Functions.ProcessQueueMessage(String message,TextWriter log)
...消息被省略....
CompleteProcessingMessageAsync消息:d3c88182-ff39-4f81-8c29-b4ce0b2062ad dequeue count:5 CopyMessageToPoisonQueueAsync消息:d3c88182-ff39-4f81-8c29-b4ce0b2062ad dequeue count:5 消息已达到MaxDequeueCount为5.将消息移至队列'01testqueue-poison'。 CopyMessageToPoisonQueueAsync消息:da643007-954a-4296-9e9a-54ebb0aec6c5 dequeue count:5 十分钟等待时间: BeginProcessingMessageAsync消息:d3c88182-ff39-4f81-8c29-b4ce0b2062ad dequeue count:6日期:2017-06-26 13:43:46 执行'Functions.ProcessQueueMessage'(Reason ='在'01testqueue'上检测到新队列消息。',Id = c22fe457-cb70-4cc8-a8a4-550cd44a8345) Test QueueProcessorFactory 执行函数时出现异常:Functions.ProcessQueueMessage CompleteProcessingMessageAsync消息:d3c88182-ff39-4f81-8c29-b4ce0b2062ad dequeue count:6 CopyMessageToPoisonQueueAsync消息:d3c88182-ff39-4f81-8c29-b4ce0b2062ad dequeue count:6 消息已达到MaxDequeueCount为5.将消息移至队列'01testqueue-poison'。 CopyMessageToPoisonQueueAsync消息:c43fd9fb-c2d7-4745-91ae-33cdc407ede6 dequeue count:6
答案 0 :(得分:1)
根据您的描述,我认为使用带有WebJobs SDK的Storage SDK 8.x会导致已知问题。以下是类似的问题:
根据我的测试,此问题暂时尚未修复。您可以按如下方式降级Storage SDK或更改CopyMessageToPoisonQueueAsync
:
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);
}