node.js - Azure IoT 和事件中心?

标签 node.js azure iot azure-eventhub cortana-intelligence

我正在尝试读取我的设备发送的事件。我正在使用 azure npm lib 来阅读我认为正确的内容。

好的,首先,在该服务的 Azure IoT Hub 帐户下有一个名为“消息传递”的选项卡。有一种称为“事件中心兼容名称”和“事件中心兼容端点”的东西。我是否必须创建一个名称为“事件中心兼容名称”的新事件中心或其他名称?我有点困惑:D 如果不是,连接字符串和主题等是什么?

现在的代码是这样的......

var azure = require('azure');

var serviceBusService = azure.createServiceBusService("Endpoint=XXXXXXXXXX.servicebus.windows.net/");
var isWaiting = false;


function waitForMessages(){
    console.log("Checking Queue...");
    isWaiting = true;
    serviceBusService.receiveQueueMessage("messages","events",function (error, receivedMessage){
        console.log(error);
        console.log(receivedMessage);
        isWaiting = false;
    });
}


// Start messages listener
setInterval(function () {
    if(!isWaiting){
        waitForMessages();
    }
}, 200);

最佳答案

事件中心兼容名称并不意味着您必须创建具有相同名称的事件中心。

IOT Hub 提供了向后兼容 Event Hub API 的端点。我认为实际的实现要复杂一些,但您可以将 IOT Hub 视为继承自 Event Hubs,或者至少是 Event Hubs 的实现。将此事件中心兼容名称与任何事件中心 SDK 或代码示例一起使用作为连接字符串的一部分。

为了解释事件中心兼容名称事件中心兼容端点的概念,您可以请参阅官方文档 Azure IoT Hub developer guide如何从事件中心兼容端点读取部分。您可以使用 Azure Service Bus SDK for .NETEvent Hubs - Event Processor Host使用 C# 从 IoT 中心读取事件。

否则有两个Azure IoT SDKs对于使用连接字符串的 NodeJS:Azure IoT Service SDK ( API Reference ) & Azure IoT Device SDK (API Reference)。

连接字符串,您可以在所有设置<中的共享访问策略选项卡的一个策略中找到它,请参阅文档 Tutorial: Get started with Azure IoT Hub 中的下图.

enter image description here

根据您从 IoT 中心读取事件的需求,您可以按照这些示例使用适用于 NodeJS 的 Azure IoT SDK 进行编码。

  1. 使用 Azure IoT Service SDK 列出您的 IoT 中心中注册的 deviceId,请参阅示例 https://github.com/Azure/azure-iot-sdks/blob/master/node/service/samples/registry_sample.js .
  2. 使用 Azure IoT Device SDK 监控来自 IoT 中心的事件,请参阅示例 https://github.com/Azure/azure-iot-sdks/blob/master/node/device/samples/remote_monitoring.js .

希望有帮助。如有任何疑问,请随时告诉我。

关于node.js - Azure IoT 和事件中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34755509/

相关文章:

javascript - johnny-five 到 arduino >>> 串口通信

javascript - 使用 Nightmare/Electron 进行动态分页(页面抓取)

node.js - 用于处理来自phonegap ft.upload 的传入请求的node.js 服务器端代码是什么?

node.js - 使用express js进行heroku部署没有发生

javascript - 慢咕噜 watch

sockets - Linux 用户空间代码,用于在 Linux 板和运行 contiki udp 发送器示例代码的每个节点之间进行通信

c# - 无法将 azure storage api nuget 包添加到我的控制台应用程序

c# - .NET Core 是否支持 Web 套接字?抛出“System.Net.WebSockets.WebSocketException 异常

java - 使用服务主体验证存储帐户

hadoop - 将node.js与hadoop平台连接