Azure IoT中心事件中心触发器:未找到有效的帐户信息组合

问题描述

我是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.

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

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

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

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

这里是其他相关文件(大部分未修改)。 function.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)"
  }
}

proxies.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": {}
}

我想念什么?

解决方法

在生产和开发(在本地测试它们)方面,我对存储帐户,实际的IoT中心及其在Azure函数上下文中的连接字符串有一些一般性的误解。

为了进行本地测试,我通过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"
    }
  ]
}