最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 7浏览 0评论

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

我已将多个设备连接到Azure Stream Analytics,这些设备将发送各种数据。 (温度,光线,湿度等)

我不知道如何读取数据Azure资源并将其显示在我在Azure上发布的Web应用程序中。例如,读取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));

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

我已将多个设备连接到Azure Stream Analytics,这些设备将发送各种数据。 (温度,光线,湿度等)

我不知道如何读取数据Azure资源并将其显示在我在Azure上发布的Web应用程序中。例如,读取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));
发布评论

评论列表 (0)

  1. 暂无评论