node.js - 如何让 cosmosdb 触发一个 azure 函数并调用另一个 http 函数
问题描述
我需要监听 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 输出绑定需要 HTTP 触发器。您正在使用 Cosmos 触发器,因此无法执行此操作。参考:https ://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-output 。
使用 HTTP 输出绑定来响应 HTTP 请求发送者。此绑定需要 HTTP 触发器,并允许您自定义与触发器请求关联的响应。
我应该在上述函数中进行常规的 http 调用吗?
是的,你可以像@Thiago Custodio 所说的那样在你的函数中进行常规的 http 调用。
推荐阅读
- javascript - 生成图的每种拓扑类型
- c# - Angular 11 从前端编辑数据库表
- flutter - 在颤动中居中一列容器,crossAxis不起作用
- typescript - 如何检查一个对象是否至少有一条记录?
- reactjs - 如何在反应中编写多语言代码?
- .htaccess - HtAccess:如果访问任何子域(不存在),则重定向到主域
- encoding - 通过 Foundations 发送的电子邮件显示 ?? 间距之间
- javascript - 如何使不和谐的 js 机器人在某个时间在不和谐的确切文本通道中发送随机消息(我制作一个列表并发送它)
- goland - 如何在 GoLand 终端中输入
- java - Maven 缩短执行中的类路径