我是靠谱客的博主 懦弱小伙,这篇文章主要介绍Azure Function EventhubTrigger本地debug的正确姿势,现在分享给大家,希望可以做个参考。

想在本地debug EventhubTrigger类型的Azure Function代码,结果用VS Code debug功能之后,就报错:

Missing value for AzureWebJobsStorage in local.settings.json.
This is required for all triggers other than httptrigger, kafkatrigger,
rabbitmqtrigger, orchestrationTrigger, activityTrigger, entityTrigger.
You can run 'func azure functionapp fetch-app-settings <functionAppName>',
specify a connection string in local.settings.json,
or use managed identity to authenticate.func

这个很好解决,只需要添加下面一句:

"AzureWebJobsStorage": "UseDevelopmentStorage=true",

到 local.settings.json 这个文件里就可以了,这个文件是在debug的时候自动产生的,因为我clone的现成的Azure Function code,不是用VS Code创建的Azure Function,如果用VS Code创建的,在创建过程中会让你选择是否使用本地debug,然后会自动给你创建。

完整的local.settings.json文件内容如下:

{  
      "IsEncrypted": false,  "Values": 
      {    
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",   
            "FUNCTIONS_WORKER_RUNTIME": "dotnet",   
            "eventhub-name": "youreventhubname",    
            "eventhub-connection-string": "youreventhubconnectionstring",    
            "eventhub-consumer-group": "youreventhubconsumergroupname"  
       }
}


但是即使我按照要求在local.settings.json文件里添加了AzureWebJobsStorage参数,保存了文件,但是VS Code依然报错:

还以为双引号,冒号,逗号写错了呢,通通检查了一遍,还是不行。那就重启VS Code,还真是,不再报错了,看来VS Code还是不够智能啊!不能够动态监测文件配置更新。

所以,这个local.settings.json文件里内容更新了,最好重启一下VS Code,否则可能更改不生效。接下来你就可以愉快的做本地debug了。

好了,本次分享就到这里。欢迎微信骚扰!

最后

以上就是懦弱小伙最近收集整理的关于Azure Function EventhubTrigger本地debug的正确姿势的全部内容,更多相关Azure内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(119)

评论列表共有 0 条评论

立即
投稿
返回
顶部