Azure WebJob QueueTrigger 得到DeleteMessage后怎么办?
Azure WebJob QueueTrigger How DeleteMessage after get it?
我在 Azure 上有一个 Web 作业,带有 QueueTrigger。作业时间长(超过30分钟)
public async static Task ProcessQueueMessageAsync([QueueTrigger(QUEUENAME)] string iJobId)
{
//doing my long job
}
我的问题是触发后如何删除队列中的消息。在时间跨度(默认为 30 秒)到来之前,消息变得不可见。我的工作时间要少得多。所以我想我必须在触发方法的开头删除消息。
当您使用 GetMessage()
方法循环而不是触发时,我找到了如何做到这一点。但是如何使用触发器来完成,因为我没有 运行 .DeleteMessage()
?
的消息对象
Answered by Michael Curd on the MSDN Forums,并在此处引用:
The SDK should already handle that. As you stated, the message will be leased (or become invisible) for 30 seconds by default. If the job takes longer than that, then the lease will be renewed. The message will not become available to another instance of the function unless the host crashes or the function throws an exception. When the function completes successfully, the message is deleted by the SDK. So you shouldn't need to write any special code for this scenario.
我在 Azure 上有一个 Web 作业,带有 QueueTrigger。作业时间长(超过30分钟)
public async static Task ProcessQueueMessageAsync([QueueTrigger(QUEUENAME)] string iJobId)
{
//doing my long job
}
我的问题是触发后如何删除队列中的消息。在时间跨度(默认为 30 秒)到来之前,消息变得不可见。我的工作时间要少得多。所以我想我必须在触发方法的开头删除消息。
当您使用 GetMessage()
方法循环而不是触发时,我找到了如何做到这一点。但是如何使用触发器来完成,因为我没有 运行 .DeleteMessage()
?
Answered by Michael Curd on the MSDN Forums,并在此处引用:
The SDK should already handle that. As you stated, the message will be leased (or become invisible) for 30 seconds by default. If the job takes longer than that, then the lease will be renewed. The message will not become available to another instance of the function unless the host crashes or the function throws an exception. When the function completes successfully, the message is deleted by the SDK. So you shouldn't need to write any special code for this scenario.