我已将多个设备连接到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));
我假设您正在使用一些快捷方式。并且您正在将设备中的事件发送到EventHub
所以现在的架构看起来像这样:
Device
- > EventHub
- > Azure StreamAnalytics
和AppService
称为my web application
Azure StreamAnalytics
只是帮你做一些聚合,计算等等。另一方面,您可以使用例如Azure Function
我建议将数据存储在存储器中,例如在Azure Storage
这是建议的架构:
Device
- > EventHub
- > Azure StreamAnalytics
或Azure Function
- > Azure Table Storage
AppService
Azure Table Storage
然后,从存储中显示Web应用程序中的数据。以下是docs的示例:
tableSvc.retrieveEntity('mytable', 'hometasks', '1', function(error, result, response){
if(!error){
// result contains the entity
}
});
可视化Azure Stream Analytics输出的最简单方法是使用Power BI,如果您有权访问它。几分钟后,您可以创建仪表板并显示值或图表。更多信息here。您的仪表板也可以使用“Power BI embedded”嵌入到您自己的应用程序中。如果要创建自己的应用程序以可视化输出,则根据延迟要求,它们有几种可能的方式。例如。您可以输出到Cosmos DB或SQL,然后使用它们的客户端库。您还可以输出到Azure功能并使用Signal R创建动态页面。如果您有任何进一步的问题,请告诉我们。