Azure-将数据从IoT中心发送到Web应用程序后端

时间:2019-07-14 22:44:33

标签: asp.net azure azure-web-app-service azure-iot-hub read-data

我正在寻找一种解决方案,以将数据从Azure IoT中心获取到还托管在Azure中的Web应用程序的后端,该Web应用程序用ASP.NET 4.6编写。 最好尽快接收原始的Json字符串。

我发现其他人建议出于类似目的使用Webhooks或Azure函数,但是这些解决方案带来的延迟确实是不可接受的。 最好是直接连接到IoT端点并获取每条消息,这是最好的。任何人都可以为我指出正确的方向吗?

2 个答案:

答案 0 :(得分:2)

您只需在Web应用程序中使用EventHub .NET SDK,连接到IoT中心的EventHub-compatible endpoint并直接在应用程序中使用事件。这具有最小的延迟,并且不涉及额外的组件。

如何指导(.NET核心,但也适用于.NET Framework):https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send#receive-events

var eventProcessorHost = new EventProcessorHost(
            EventHubName,
            PartitionReceiver.DefaultConsumerGroupName,
            EventHubConnectionString,
            StorageConnectionString,
            StorageContainerName);

// Registers the Event Processor Host and starts receiving messages
await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();

答案 1 :(得分:0)

Azure SignalR Service可以帮助将消息广播到Web App实例。

Azure IoT中心与Azure SignalR服务之间没有直接集成。基本上,您可以使用两种模式进行此集成,例如 PULL-PUSH PUSH-PUSH

以下屏幕显示了这些集成模式:

enter image description here

请注意,当订阅者(消费者)对于按顺序处理事件不是很关键时,带有Azure事件网格的 PUSH-PUSH 模式适用于解决方案。