簡體   English   中英

如何使用 Azure 函數綁定發送預定的服務總線隊列消息?

[英]How to use an Azure Function Binding to send a scheduled Service Bus Queue message?

我有一個用 node.js 編寫的 Azure 函數,它使用輸出綁定成功地將消息發送到 Azure 服務總線隊列。

如何仍使用綁定語法將預定消息發送到同一個隊列? 如果可能的話,我寧願在不安裝 node.js sdk 的情況下執行此操作。

綁定文檔沒有提到預定的消息。 然而,有趣的是,這個評論已經在 Functions github 問題存儲庫上發表了幾次:

至少對於 C# 和 Node.js(為什么不在 F# 中),服務總線隊列輸出已經支持這一點,例如,如果您創建並放置多個消息,例如到 IAsyncCollector 或創建 BrokeredMessage。 在您的外發消息中,您可以控制預定的排隊時間:

outgoingMessage.ScheduledEnqueueTimeUtc = DateTimeOffset.UtcNow.AddSeconds(10)

無論如何,這是我當前的代碼,可以很好地立即傳遞消息:

函數.json

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name" : "queueOutput",
      "queueName" : "scheduler",
      "connection" : "AZURE_SERVICEBUS_CONNECTION_STRING",
      "type" : "serviceBus",
      "direction" : "out"
    }
  ]
}

索引.js

module.exports = function (context, req) {

  context.log('Scheduler function processed a request.');

  context.bindings.queueOutput = req.body;

  context.res = {
    "status": 200,
    "body": {
      "message": "Successfully sent message to Queue"
    } 
  };

  context.done();

};

使用基於時間的觸發器語法(CRON 調度)怎么樣...假設我沒有誤解這個問題

{
  "name": "function",
  "type": "timerTrigger",
  "direction": "in",
  "schedule": "0 */5 * * * *"
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM