【问题标题】:How can I add eventGrid to a http trigger in Azure Functions in NodeJS?如何在 NodeJS 中的 Azure Functions 中将 eventGrid 添加到 http 触发器?
【发布时间】:2021-10-13 23:06:12
【问题描述】:

目标是将数据写入 Azure 中的主题,但我收到以下错误:

“PostBooking”函数出错:绑定类型“eventGrid”未注册。请确保类型正确并安装了绑定扩展。

我在本地开发这个。

index.js

module.exports = async function (context, req) {
let booking = req.body;
var timeStamp = new Date().toISOString();
context.bindings.bookings = booking;

context.bindings.outputEvent = {
    id: 'message-id'+timeStamp,
    subject: 'Booking',
    dataVersion: '1.0',
    eventType: 'event-type',
    data: booking,
    eventTime: timeStamp
};
context.res = {
    status: 201,
    headers: {
        "content-type": "application/json"
    },
    body: {
        message: booking.id
    }
}
context.done();

}

function.js

    {
  "disabled": false,
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ],
      "route": "bookings/"
    },
    {
      "name": "outputEvent",
      "type": "eventGrid",
      "topicEndpointUri": "{hidden}",
      "topicKeySetting": "{hidden}",
      "direction": "out"
    },
    {
      "name": "bookings",
      "type": "cosmosDB",
      "direction": "out",
      "databaseName": "{hidden}",
      "collectionName": "bookings",
      "createIfNotExists": true,
      "connectionStringSetting": "CosmosDB"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

错误信息

我不知道该怎么办?

【问题讨论】:

标签: node.js azure azure-functions serverless azure-eventgrid


【解决方案1】:

类似问题 github.com/Azure/azure-functions-extension-bundles/issues/10。 eventGrid 的绑定刚刚添加到 Microsoft.Azure.Functions.ExtensionBundle 中,但最新版本尚未发布。

【讨论】:

    【解决方案2】:

    我后来发现还不能将 eventgrid 添加到 http 触发器,只能添加事件网格触发器。要将事件发布到事件网格,我使用了此代码。 Index.js

    【讨论】:

      猜你喜欢
      • 2018-10-26
      • 2022-01-19
      • 2022-06-28
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 2018-07-05
      • 1970-01-01
      • 2017-10-29
      相关资源
      最近更新 更多