【问题标题】:Azure cosmos db triggerAzure cosmos 数据库触发器
【发布时间】:2017-09-05 14:26:03
【问题描述】:

是否可以在 Azure 管道中调用 cosmos db 触发器?管道只是将数据从 azrue 存储复制到 cosmos db 集合,需要调用预触发器。如何为复制活动指定触发器ID?

【问题讨论】:

  • 您在使用 Azure Functions 吗?您能否描述一下您正在使用或计划构建的事件管道类型?当您说 Azure 存储时,您是指 Blob 吗?排队?桌子?
  • @MatiasQuaranta,说到 Azure 存储,我指的是 Blob。我的管道只是将数据集形式 blob 复制到 cosmos db。而且我知道如何调用触发器,例如从 Node.js documentdb 客户端 api 调用。但我应该在管道中进行。
  • 如果我理解正确的话,当 Blob 上传到 Azure 存储时,您想将数据保存到 Cosmos DB 中吗?而你要存储的信息是 Blob 的内容还是它的一些属性?
  • 是的,我认为有必要为此编写自定义活动来实现触发业务逻辑。

标签: azure azure-cosmosdb


【解决方案1】:

根据您的说法,您可以通过使用带有 Blob TriggerDocumentDB output binding 的 Azure Functions 来解决此问题。

functions.json 类似:

{
    "disabled": false,
    "bindings": [
        {
            "name": "myBlob",
            "type": "blobTrigger",
            "direction": "in",
            "path": "<name-of-the-folder-where-files-get-uploaded>",
            "connection":"MyStorageAccount"
        },
        {
          "name": "documentToSave",
          "type": "documentDB",
          "databaseName": "MyDatabase",
          "collectionName": "MyCollection",
          "createIfNotExists": true,
          "connection": "MyAccount_COSMOSDB",     
          "direction": "out"
        }
    ]
}

函数体可能是这样的:

// Blob trigger binding to a CloudBlockBlob
#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Blob;

public static void Run(CloudBlockBlob myBlob, out object documentToSave, TraceWriter log)
{
    // some logic to read the blob and parse it

    documentToSave = new {
        id = "some value",
        .. other properties here
      };
}

【讨论】:

  • 感谢您的清晰解释。但是我应该在复制管道启动时调用 cosmos db 预触发。在每次复制时,我都应该检查 blob 文档是否存在它 cdb 集合,如果为真则替换它。这是 cdb 预触发业务逻辑。 Blob 触发器不能解决我的问题。
  • Blob 触发器将在您修改/上传文档时触发。 DocumentDB 输出绑定将保存或更新文档。您必须确保正确设置了文档的 id 属性(可能与文档本身相关,例如名称)。
  • 我在尝试将已经存在的 json 复制到 cosmos db 集合时出错。我希望使用上述 cosmos db 预触发器来解决此问题。
猜你喜欢
  • 1970-01-01
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 2022-06-23
  • 2021-10-03
  • 2019-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多