代码之家  ›  专栏  ›  技术社区  ›  Stefan Wick MSFT

Azure功能-如何为我的IoTHub消息设置IoTHubTrigger?

  •  1
  • Stefan Wick MSFT  · 技术社区  · 6 年前

    如何正确设置和配置IoTHubTrigger以触发IoTHub消息的Azure函数(C#)?在何处以及如何插入IoTHub的连接字符串?

    1 回复  |  直到 4 年前
        1
  •  14
  •   Stefan Wick MSFT    6 年前

    使用Visual Studio 2017的步骤:

    1. 首先确保您拥有最新版本的Azure函数和Web作业工具

    enter image description here

    1. 转到文件->新建->项目->Azure功能并选择“IoT集线器触发器” enter image description here

    2. 选择功能V1或V2(了解它们的区别 here

    3. 打开local.settings.json并输入连接字符串的键/值对:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
            "ConnectionString":  "<your connection string>"
        }
    }
    

    如果使用函数V1 ,使用在门户中获得的IoTHub连接字符串: enter image description here

    如果使用函数V2 ,使用您的IoTHub的EventHub兼容端点,该端点是从以下位置在门户中获得的: enter image description here

    1. enter image description here

    使用Azure门户的步骤

    1. 创建新的函数应用程序资源并选择EventHub触发器模板 enter image description here

    2. 点击EventHub Connection的“New”,然后选择IotHub和所需的hub enter image description here

    3. 编辑并保存你的功能代码-你现在开始运行!

    4. 切换到“监视”查看事件的进展 enter image description here

    创建IoTHub触发器Azure函数的更多选项

    a) 将VS代码与 Azure Functions Extension
    Azure Functions Core Tools

        2
  •  0
  •   Crocky    5 年前

    我还需要安装一个NuGet包Microsoft.Azure.WebJobs.Extensions.EventHubs

        3
  •  0
  •   draco951    5 年前
    推荐文章