webjob QueueTrigger 不会从队列中删除消息
webjob QueueTrigger does not delete message from the queue
.NET Core 2.2, WebJobs SDK 3.0
我有一个从队列中获取消息的网络作业。像这样的标准 QueueTrigger
public void ProcessQueueMessage(
[QueueTrigger("%WebJobs:WorkerQueueName%")] CloudQueueMessage queueMessage,
ILogger log)
在流程结束时,我将消息写入另一个队列(存档)。
函数成功完成,但消息保留在源队列中
在存储资源管理器中我看到了这个(在这个例子中我有 3 条待处理的消息)
消息在 10 分钟后再次出队。
我怎样才能使消息在我的函数成功时出队?
顺便说一句,我的队列配置是
BatchSize 1
MaxDequeueCount 2
MaxPollingInterval 00:00:04
VisibilityTimeout 02:00:00
SDK 应该已经处理好了。
默认情况下,消息将租用(或变得不可见)30 秒。如果作业花费的时间超过该时间,则将续订租约。除非主机崩溃或函数抛出异常,否则该消息将无法用于该函数的另一个实例。函数成功完成后,消息将被 SDK 删除。
When a message is retrieved from the queue, the response includes the message and a pop receipt value, which is required to delete the message. The message is not automatically deleted from the queue, but after it has been retrieved, it is not visible to other clients for the time interval specified by the visibilitytimeout
parameter. The client that retrieves the message is expected to delete the message after it has been processed, and before the time specified by the TimeNextVisible
element of the response, which is calculated based on the value of the visibilitytimeout
parameter. The value of visibilitytimeout
is added to the time at which the message is retrieved to determine the value of TimeNextVisible
.
因此您不需要编写任何特殊代码来从队列中删除消息。
原来是我用获取到的queueMessage
对象作为参数直接放到另一个队列里面,估计SDK搞糊涂了
public void ProcessQueueMessage(
[QueueTrigger("%WebJobs:WorkerQueueName%")] CloudQueueMessage queueMessage,
ILogger log)
所以我改变了它,在将它放入另一个队列之前创建了一个新的 CloudQueueMessage 对象。
var newMessage = new CloudQueueMessage(queueMessage.AsString);
现在,当我的函数 returns 时,消息已从队列中正确删除。
.NET Core 2.2, WebJobs SDK 3.0
我有一个从队列中获取消息的网络作业。像这样的标准 QueueTrigger
public void ProcessQueueMessage(
[QueueTrigger("%WebJobs:WorkerQueueName%")] CloudQueueMessage queueMessage,
ILogger log)
在流程结束时,我将消息写入另一个队列(存档)。
函数成功完成,但消息保留在源队列中
在存储资源管理器中我看到了这个(在这个例子中我有 3 条待处理的消息)
消息在 10 分钟后再次出队。
我怎样才能使消息在我的函数成功时出队?
顺便说一句,我的队列配置是
BatchSize 1
MaxDequeueCount 2
MaxPollingInterval 00:00:04
VisibilityTimeout 02:00:00
SDK 应该已经处理好了。
默认情况下,消息将租用(或变得不可见)30 秒。如果作业花费的时间超过该时间,则将续订租约。除非主机崩溃或函数抛出异常,否则该消息将无法用于该函数的另一个实例。函数成功完成后,消息将被 SDK 删除。
When a message is retrieved from the queue, the response includes the message and a pop receipt value, which is required to delete the message. The message is not automatically deleted from the queue, but after it has been retrieved, it is not visible to other clients for the time interval specified by the
visibilitytimeout
parameter. The client that retrieves the message is expected to delete the message after it has been processed, and before the time specified by theTimeNextVisible
element of the response, which is calculated based on the value of thevisibilitytimeout
parameter. The value ofvisibilitytimeout
is added to the time at which the message is retrieved to determine the value ofTimeNextVisible
.
因此您不需要编写任何特殊代码来从队列中删除消息。
原来是我用获取到的queueMessage
对象作为参数直接放到另一个队列里面,估计SDK搞糊涂了
public void ProcessQueueMessage(
[QueueTrigger("%WebJobs:WorkerQueueName%")] CloudQueueMessage queueMessage,
ILogger log)
所以我改变了它,在将它放入另一个队列之前创建了一个新的 CloudQueueMessage 对象。
var newMessage = new CloudQueueMessage(queueMessage.AsString);
现在,当我的函数 returns 时,消息已从队列中正确删除。