[英]Create a nodejs web app that reads data from AZURE. (Stream analytics or Event Hubs or Log analytics)
I have connected several devices to Azure Stream Analytics that will send in various data. 我已将多个设备连接到Azure Stream Analytics ,这些设备将发送各种数据。 ( Temp, light, humidity and etc )
(温度,光线,湿度等)
I am not sure how can I read data Azure Resources and display it on my web application that I've published on Azure . 我不确定如何读取数据Azure资源并将其显示在我在Azure上发布的Web应用程序中。 For example, reading device_name, device's data.
例如,读取device_name,即设备的数据。
What I need is probably a sample code that reads some data from Azure and then display it on a simple 'h1' or 'p' tag. 我需要的是一个示例代码,该示例代码从Azure读取一些数据,然后将其显示在简单的“ h1”或“ p”标记上。
PS: I've seen lots of tutorial that teaches how to publish web app to Azure. PS:我看过很多教程,教如何将Web应用发布到Azure。 But there're hardly any tutorials that specifically teaches how to read and grab data from Azure Resources.
但是几乎没有任何教程专门讲授如何从Azure资源读取和获取数据。
You can use Azure SDK for Node.js to manage Azure resources. 您可以使用Azure SDK for Node.js来管理Azure资源。
This is an example retrive information about an existing event hub. 这是检索有关现有事件中心的信息的示例。 And here is the Azure Node SDK reference .
这是Azure Node SDK 参考 。
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));
I assume that you are using some shortcuts. 我假设您正在使用一些快捷方式。 And that you are sending events from devices to
EventHub
并且您正在将事件从设备发送到
EventHub
So the architecture right now looks like this: 所以现在的架构看起来像这样:
Device
-> EventHub
-> Azure StreamAnalytics
Device
-> EventHub
> Azure StreamAnalytics
and AppService
called my web application
和
AppService
调用了my web application
Azure StreamAnalytics
just help you to do some aggregation, calculation and so on. Azure StreamAnalytics
只是帮助您进行一些聚合,计算等等。 On the other hand, you can use eg Azure Function 另一方面,您可以使用例如Azure函数
I would suggest to store data in storage eg in Azure Storage 我建议将数据存储在存储中,例如在Azure存储中
This is proposed architecture: 这是建议的体系结构:
Device
-> EventHub
-> Azure StreamAnalytics
or Azure Function
-> Azure Table Storage
Device
-> EventHub
> Azure StreamAnalytics
或Azure Function
> Azure Table Storage
AppService
<-> Azure Table Storage
AppService
<-> Azure Table Storage
And later display data in your web app from storage. 然后在存储中在Web应用程序中显示数据。 Here is example from docs:
这是来自docs的示例:
Retrieve an entity by key 通过键检索实体
tableSvc.retrieveEntity('mytable', 'hometasks', '1', function(error, result, response){
if(!error){
// result contains the entity
}
});
The easiest way to visualize the output of Azure Stream Analytics is to use Power BI, if you have access to it. 可视化Azure流分析输出的最简单方法是使用Power BI(如果您可以访问它)。 In few minutes you can create a dashboard and show values or graph.
几分钟后,您可以创建仪表板并显示值或图形。 More info here .
更多信息在这里 。 Your dashboard can be also embedded in your own app using "Power BI embedded".
您的仪表板也可以使用“ Power BI Embedded”嵌入到自己的应用程序中。 If you want to create your own application to visualize output, they are several possible ways depending of your latency requirements.
如果要创建自己的应用程序以可视化输出,则根据延迟要求,有几种可能的方法。 Eg you can output to Cosmos DB or SQL and then use their client library.
例如,您可以输出到Cosmos DB或SQL,然后使用它们的客户端库。 You can also output to Azure Function and use Signal R to create dynamic page.
您还可以输出到Azure Function并使用Signal R创建动态页面。 Let us know if you have any further question.
让我们知道您是否还有其他问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.