1. <i id='AJayi'><tr id='AJayi'><dt id='AJayi'><q id='AJayi'><span id='AJayi'><b id='AJayi'><form id='AJayi'><ins id='AJayi'></ins><ul id='AJayi'></ul><sub id='AJayi'></sub></form><legend id='AJayi'></legend><bdo id='AJayi'><pre id='AJayi'><center id='AJayi'></center></pre></bdo></b><th id='AJayi'></th></span></q></dt></tr></i><div id='AJayi'><tfoot id='AJayi'></tfoot><dl id='AJayi'><fieldset id='AJayi'></fieldset></dl></div>
        <tfoot id='AJayi'></tfoot>

        <small id='AJayi'></small><noframes id='AJayi'>

        <legend id='AJayi'><style id='AJayi'><dir id='AJayi'><q id='AJayi'></q></dir></style></legend>

        • <bdo id='AJayi'></bdo><ul id='AJayi'></ul>

        用于写入队列的 Azure 函数 - 我可以设置元数据吗?

        时间:2023-10-25

          <small id='3PN5Z'></small><noframes id='3PN5Z'>

              <tbody id='3PN5Z'></tbody>

            <legend id='3PN5Z'><style id='3PN5Z'><dir id='3PN5Z'><q id='3PN5Z'></q></dir></style></legend>

              1. <i id='3PN5Z'><tr id='3PN5Z'><dt id='3PN5Z'><q id='3PN5Z'><span id='3PN5Z'><b id='3PN5Z'><form id='3PN5Z'><ins id='3PN5Z'></ins><ul id='3PN5Z'></ul><sub id='3PN5Z'></sub></form><legend id='3PN5Z'></legend><bdo id='3PN5Z'><pre id='3PN5Z'><center id='3PN5Z'></center></pre></bdo></b><th id='3PN5Z'></th></span></q></dt></tr></i><div id='3PN5Z'><tfoot id='3PN5Z'></tfoot><dl id='3PN5Z'><fieldset id='3PN5Z'></fieldset></dl></div>
              2. <tfoot id='3PN5Z'></tfoot>
                  <bdo id='3PN5Z'></bdo><ul id='3PN5Z'></ul>
                  本文介绍了用于写入队列的 Azure 函数 - 我可以设置元数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以从 这个页面看到 当它们用作触发器时,您可以简单地访问队列消息元数据属性,但我想做相反的事情.我有一个将消息写入队列的 Azure 函数,但它当前具有默认的过期时间,我想设置一个更短的过期时间,以便它们只在队列中存活很短的时间.

                  I can see from this page that you can access a queue message metadata properties simply enough when they are used as a trigger, but I want to do the opposite. I have an Azure function which writes messages to a queue, but it current has the default Expiration Time and I want to set a much shorter expiration time so they only live on the queue for a very short period.

                  有没有办法在将消息从 Azure Function 写入队列时设置过期时间?

                  Is there a way when writing the message to the queue from the Azure Function to set the Expiration time?

                  谢谢

                  编辑 1:一个警告是我不提前知道队列的名称.那是传入消息的一部分,因此将 queuename 设置为输出绑定的参数我按照@Mikhail 的建议进行了更改.这是它的功能:

                  EDIT 1: One caveat is that I dont know the name of the queue ahead of time. That is part of the incoming message, so the queuename is set as a parameter of the output binding I made the change as recommended by @Mikhail. Here is the function as it stands:

                  #r "Microsoft.WindowsAzure.Storage"
                  #r "Newtonsoft.Json"
                  
                  using System;
                  using Microsoft.WindowsAzure.Storage.Queue;
                  using Newtonsoft.Json;
                  
                  public static void Run(MyType myEventHubMessage, CloudQueue outputQueue, TraceWriter log)
                  {
                      var deviceId = myEventHubMessage.DeviceId;
                      var data = JsonConvert.SerializeObject(myEventHubMessage);
                      var msg = new CloudQueueMessage(data);
                      log.Info($"C# Event Hub trigger function processed a message: {deviceId}");
                      outputQueue.AddMessage(msg, TimeSpan.FromMinutes(3), null, null, null);
                  
                  }
                  
                  public class MyType
                  {
                    public string DeviceId { get; set; }
                    public double Field1{ get; set; }
                    public double Field2 { get; set; }
                    public double Field3 { get; set; }
                  }
                  

                  以及我的function.json中的输出绑定:

                  And the output binding in my function.json:

                  {
                  "type": "CloudQueue",
                  "name": "$return",
                  "queueName": "{DeviceId}",
                  "connection": "myConn",
                  "direction": "out"
                  }
                  

                  推荐答案

                  将参数类型改为CloudQueue,然后手动添加消息并设置过期时间属性(或者更确切地说是生存时间).

                  Change the type of your parameter to CloudQueue, then add a message manually and set the expiration time property (or rather Time To Live).

                  public static void Run(string input, CloudQueue outputQueue)
                  {
                      outputQueue.AddMessage(
                          new CloudQueueMessage("Hello " + input),
                          TimeSpan.FromMinutes(5));
                  }
                  

                  如果您的输出队列名称取决于请求,您可以使用命令式绑定:

                  if your output queue name depends on request, you can use imperative binding:

                  public static void Run(string input, IBinder binder)
                  {
                      string outputQueueName = "outputqueue " + input;
                      QueueAttribute queueAttribute = new QueueAttribute(outputQueueName);
                      CloudQueue outputQueue = binder.Bind<CloudQueue>(queueAttribute);
                      outputQueue.AddMessage(
                          new CloudQueueMessage("Hello " + input),
                          TimeSpan.FromMinutes(5));
                  }
                  

                  这篇关于用于写入队列的 Azure 函数 - 我可以设置元数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Azure Function v2 自定义 Application Insight TelemetryInitia 下一篇:如何引用“便携式"?来自 Azure 云函数的 .NET 程序集?

                  相关文章

                  <small id='5n9hk'></small><noframes id='5n9hk'>

                    <bdo id='5n9hk'></bdo><ul id='5n9hk'></ul>

                • <tfoot id='5n9hk'></tfoot>

                  1. <i id='5n9hk'><tr id='5n9hk'><dt id='5n9hk'><q id='5n9hk'><span id='5n9hk'><b id='5n9hk'><form id='5n9hk'><ins id='5n9hk'></ins><ul id='5n9hk'></ul><sub id='5n9hk'></sub></form><legend id='5n9hk'></legend><bdo id='5n9hk'><pre id='5n9hk'><center id='5n9hk'></center></pre></bdo></b><th id='5n9hk'></th></span></q></dt></tr></i><div id='5n9hk'><tfoot id='5n9hk'></tfoot><dl id='5n9hk'><fieldset id='5n9hk'></fieldset></dl></div>

                    1. <legend id='5n9hk'><style id='5n9hk'><dir id='5n9hk'><q id='5n9hk'></q></dir></style></legend>