创建一个从 AZURE 读取数据的 nodejs Web 应用程序。 (流分析或事件中心或日志分析)

Create a nodejs web app that reads data from AZURE. (Stream analytics or Event Hubs or Log analytics)

我已将多个设备连接到 Azure 流分析,它们将发送各种数据。 (温度、光照、湿度等)

我不确定如何读取数据 Azure Resources在我发布在 蔚蓝。例如读取device_name,设备数据

我需要的可能是一个示例代码,它从 Azure 读取一些数据,然后将其显示在一个简单的 'h1' 或 'p' 标记上。

PS:我看过很多教如何将 Web 应用程序发布到 Azure 的教程。但是几乎没有任何教程专门教如何从 Azure 资源中读取和获取数据。

您可以使用 Azure SDK for Node.js 来管理 Azure 资源。

这是一个关于现有事件中心的检索信息示例。这是 Azure Node SDK reference.

const msRestAzure = require('ms-rest-azure');
const EventHubManagement = require('azure-arm-eventhub');

const resourceGroupName = 'testRG';
const namespaceName = 'testNS';
const eventHubName = 'testEH';
const subscriptionId = 'your-subscription-id';

msRestAzure
  .interactiveLogin()
  .then(credentials => {
    const client = new EventHubManagement(credentials, subscriptionId);
    return client.eventHubs.get(resourceGroupName, namespaceName, eventHubName);
  })
  .then(zones => console.dir(zones, { depth: null, colors: true }))
  .catch(err => console.log(err));

我假设您正在使用一些快捷方式。 并且您正在将事件从设备发送到 EventHub

所以现在的架构是这样的:

Device -> EventHub -> Azure StreamAnalytics

AppService 称为 my web application

Azure StreamAnalytics只是帮你做一些汇总,计算等等。 另一方面,您可以使用例如Azure Function

我建议将数据存储在存储器中,例如在 Azure Storage

这是提议的架构:

Device -> EventHub -> Azure StreamAnalyticsAzure Function -> Azure Table Storage

AppService <-> Azure Table Storage

稍后在您的网络应用程序中显示来自存储的数据。 这是文档中的示例:

Retrieve an entity by key

tableSvc.retrieveEntity('mytable', 'hometasks', '1', function(error, result, response){
  if(!error){
    // result contains the entity
  }
});

可视化 Azure 流分析输出的最简单方法是使用 Power BI(如果您有权访问它)。在几分钟内,您可以创建一个仪表板并显示值或图表。更多信息 here。您的仪表板也可以使用 "Power BI embedded" 嵌入到您自己的应用程序中。 如果您想创建自己的应用程序来可视化输出,根据您的延迟要求,有几种可能的方法。例如。您可以输出到 Cosmos DB 或 SQL,然后使用它们的客户端库。您还可以输出到 Azure Function 并使用 Signal R 创建动态页面。 如果您还有其他问题,请告诉我们。