【问题标题】:Azure IoT Hub (Event Hub) trigger: No valid combination of account information foundAzure IoT 中心(事件中心)触发器:找不到有效的帐户信息组合
【发布时间】:2021-01-18 09:23:39
【问题描述】:

我是 Azure 新手,目前正在研究 IoT 中心的快速入门here

到目前为止,将遥测数据从设备发送到 IoT 中心并使用后端应用程序进行读取。

我安装了vs代码扩展并成功完成了Azure函数here的HTTP触发示例。

在下一步中,我尝试配置 IoT 中心(事件中心)Azure 功能。这会导致在本地测试时出现以下错误:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.funcexample'. Microsoft.WindowsAzure.Storage: No valid combination of account information found.

我在local.settings.json中添加了IoT Hub的Event Hub-compatible endpoint字符串:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "Endpoint=sb://.../;SharedAccessKeyName=iothubowner;SharedAccessKey=...;EntityPath=...",
    "FUNCTIONS_WORKER_RUNTIME": "node"
  }
}

我注意到SharedAccessKey 通过az iot hub policy show --name service --query primaryKey --hub-name {your IoT Hub name} 与 Azure 门户中的密钥不匹配。这两个键都会导致上述警告。 Edit1:SharedAccessKeys 对于服务和 iothubowner 是不同的。

Edit2:我认为我的主要问题与连接字符串有关。需要什么连接字符串以及它的格式。而且,连接字符串应该放在哪个文件/设置中?

这里是其他相关文件(大部分未触及)。 函数.json

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "IoTHubMessages",
      "direction": "in",
      "eventHubName": "samples-workitems",
      "connection": "AzureWebJobsStorage",
      "cardinality": "many",
      "consumerGroup": "$Default"
    }
  ]
}

index.js

module.exports = function (context, IoTHubMessages) {
    context.log(`JavaScript eventhub trigger function called for message array: ${IoTHubMessages}`);
    
    IoTHubMessages.forEach(message => {
        context.log(`Processed message: ${message}`);
    });

    context.done();
};

host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }
}

proxy.json:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {}
}

package.json:

{
  "name": "funcexample",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {},
  "devDependencies": {}
}

我错过了什么?

【问题讨论】:

标签: azure azure-functions azure-iot-hub


【解决方案1】:

我对存储帐户、实际 IoT 中心及其在生产和开发中 Azure Functions 上下文中的连接字符串有一些普遍的误解(在本地测试它们)。

为了在本地进行测试,我通过npm install -g azurite 安装了本地存储模拟器Azurite,并为local.settings.json 进行了以下设置

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
    "ConnectionString": "Endpoint=sb://.../;SharedAccessKeyName=...;SharedAccessKey=...;EntityPath=...",
    "FUNCTIONS_WORKER_RUNTIME": "node"
  }
}

function.json

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "IoTHubMessages",
      "direction": "in",
      "eventHubName": "samples-workitems",
      "connection": "ConnectionString",
      "cardinality": "many",
      "consumerGroup": "$Default"
    }
  ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-04
    • 2018-01-13
    • 1970-01-01
    • 2018-03-20
    • 1970-01-01
    • 2023-02-01
    • 2017-10-07
    • 2019-03-24
    相关资源
    最近更新 更多