使用 Azure webjobs 和队列存储在给定时间执行

Use Azure webjobs and queue storage to execute at a given time

我的目标是将消息推送到 Azure 队列,并让 webjob 在给定时间处理它。例如。 { 消息:"remember the milk",时间:2016-02-10-10:10:00}

我可以天真地通过使消息出列、检查时间戳并在时间未到时将其放回队列来完成此操作。

在 Azure 世界中是否有更惯用的方法来执行此操作?

您可以设置 initialVisibilityDelay:

[DoesServiceRequestAttribute]
public void AddMessage(
    CloudQueueMessage message,
    Nullable<TimeSpan> timeToLive = null,
    Nullable<TimeSpan> initialVisibilityDelay = null,
    QueueRequestOptions options = null,
    OperationContext operationContext = null
)

当延迟超时时,消息将可见:

initialVisibilityDelay Type: System.Nullable A TimeSpan specifying the interval of time from now during which the message will be invisible. If null then the message will be visible immediately.

MSDN:microsoft.windowsazure.storage.queue.cloudqueue.addmessage