Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 [英] Azure Functions: CosmosDBTrigger not triggering in Visual Studio

查看:21
本文介绍了Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL;DR:这个例子 在 VS2017 中不适合我.

TL;DR: This example is not working for me in VS2017.

我有一个 Azure Cosmos DB,并希望在其中添加或更新某些内容时触发一些逻辑.为此,CosmosDBTrigger 应该很棒.

I have an Azure Cosmos DB and want to fire some logic when something adds or updates there. For that, CosmosDBTrigger should be great.

教程 演示在 Azure 门户中创建触发器,它适用于我.但是,在 Visual Studio(15.5.4,目前最新)中做同样的事情不会.

Tutorial demonstrates creating trigger in Azure Portal and it works for me. However, doing just the same thing in Visual Studio (15.5.4, latest by now) does not.

我使用默认 Azure Functions 模板、预定义 Cosmos DB 触发器和几乎默认 代码:

I use the default Azure Functions template, predefined Cosmos DB trigger and nearly default code:

[FunctionName("TestTrigger")]
public static void Run(    
    [CosmosDBTrigger("Database", "Collection", ConnectionStringSetting = "myCosmosDB")]
    IReadOnlyList<Document> input,
    TraceWriter log)
    {
        log.Info("Documents modified " + input.Count);
        log.Info("First document Id " + input[0].Id);
    }

应用程序运行没有错误但是当我实际在数据库中执行操作时没有任何反应.所以我无法调试东西并实际实现一些必需的逻辑.

App runs without errors but nothing happens when I actually do stuff in the database. So I cannot debug things and actually implement some required logic.

连接字符串local.settings.json中指定,被考虑.如果我故意犯规,触发吐出运行时错误.

Connection string is specified in the local.settings.json and is considered. If I deliberately foul it, trigger spits runtime errors.

看起来连接字符串指向了错误的数据库.但这正是我在通过 Azure 门户制作的触发器中拥有的一个复制粘贴字符串.

It all looks like the connection string is to a wrong database. But it is exactly the one, copypasted, string I have in the trigger made via Azure Portal.

我哪里出错了?我还能检查什么?

推荐答案

根据您的评论,您同时为同一个集合和同一个租约集合同时运行门户和本地应用程序.

Based on your comment, you were running both portal and local Apps at the same time for the same collection and the same lease collection.

这意味着两个应用程序在收集处理上相互竞争锁定(租约).门户应用程序在您的案例中获胜,获得了租约,因此本地应用程序无所事事.

That means both Apps were competing to each other for locks (leases) on collection processing. The portal App won in your case, took the lease, so the local App was sitting doing nothing.

这篇关于Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆