【问题标题】:How to have an azure function triggered by cosmosdb and call another http fuction如何让 cosmos db 触发一个 azure 函数并调用另一个 http 函数
【发布时间】:2021-03-26 09:58:48
【问题描述】:

我需要监听 azure cosmos db 的变化,然后根据收到的信息对另一个 api 进行 POST 调用。

我添加了这个function.json

{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "input",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "validAppsTrigger2_ConnectionString",
      "databaseName": "dev",
      "collectionName": "validApps",
      "createLeaseCollectionIfNotExists": true
    },
    {
      "name": "response",
      "direction": "out",
      "type": "http"
    }
  ]
}

这是我的 index.js

module.exports = function (context, input) {
    context.log('Document Id: ', input[0].id);
    // should I call http manually here?
    context.done();
};

但我不确定我应该如何从那里调用另一个 azure http 函数,

  • 我需要out 绑定吗?
  • 我应该只在上述函数中进行常规 http 调用吗?

【问题讨论】:

  • 只需向其他函数端点发出 http 请求
  • @ThiagoCustodio 是否意味着我不需要 out 绑定,对吗?
  • 正确,只是一个普通的http请求

标签: node.js azure azure-functions azure-cosmosdb


【解决方案1】:

我需要外绑定吗?

不,HTTP 输出绑定需要 HTTP 触发器。您正在使用 Cosmos 触发器,所以无法执行此操作。参考:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-output

使用 HTTP 输出绑定来响应 HTTP 请求发送者。 此绑定需要 HTTP 触发器,并允许您自定义 与触发器的请求相关联的响应。

我是否应该在上述函数中进行常规的 http 调用?

是的,你可以像@Thiago Custodio 所说的那样在你的函数中进行常规的 http 调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多