简体   繁体   中英

How can I add eventGrid to a http trigger in Azure Functions in NodeJS?

The goal is to write data to a topic in Azure, but I receive the following error:

The 'PostBooking' function is in error: The binding type(s) 'eventGrid' are not registered. Please ensure the type is correct and the binding extension is installed.

I develop this locally.

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"
    }
  ]
}

error message在此处输入图像描述

I don't know what to do?

A similar issue github.com/Azure/azure-functions-extension-bundles/issues/10. The binding eventGrid has just been added into Microsoft.Azure.Functions.ExtensionBundle , but the latest version has not released yet.

I later found out that it isn't possible to add eventgrid to http trigger yet, only event grid trigger. To publish events to event grid, I have used this code. Index.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM