如何使用 Azure 事件网格发布到队列来覆盖默认过期时间?

How to override default expiration time with Azure Event Grid publishing to queue?

我在 Azure Blob 存储上创建了事件网格订阅,它会在每次 blob created/modified 时向 Azure 队列发送消息。消息使用默认 TTL 插入,即 7 天。有没有办法改变这个参数?我想将过期时间延长至至少 14 天。

AEG 订阅无法更改任何 属性 发送到事件处理程序资源的消息。

但是,作为解决方法,可以使用 EventGridTrigger 函数和 CloudQueue 输出绑定到存储队列。

以下代码片段是您的解决方案的 EventGridTrigger 函数示例:

run.csx:

#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public static async Task Run(JObject eventGridEvent, CloudQueue outputQueue, ILogger log)
{
    log.LogInformation(eventGridEvent.ToString());

    await outputQueue.AddMessageAsync(new CloudQueueMessage(eventGridEvent.ToString()), 
       TimeSpan.FromDays(14),    // TTL
       TimeSpan.FromSeconds(0), 
       new QueueRequestOptions(),
       new OperationContext());      
}

function.json:

{
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "eventGridEvent",
      "direction": "in"
    },
    {
      "name": "outputQueue",
      "type": "queue",
      "direction": "out",
      "queueName": "test",
      "connection": "myaccount_STORAGE"
    }
  ]
}