2

I'm searching for a solution to get data from the Azure IoT Hub to the backend of a Web App also hosted in Azure which is written in ASP.NET 4.6. It would be best to just receive the raw Json string as fast as possible.

I found others suggesting using Webhooks or Azure functions for a similar purpose but the delay these solutions bring aren't really acceptable. It would be best to just connect directly to the IoT endpoint and get every message as it comes in. Can anybode please point me to the right direction?

rEsTrisA
  • 27
  • 6
  • So why use IoT Hub? Can't you send the data directly to your Web App? – CSharpRocks Jul 14 '19 at 23:40
  • I only mentioned a small fraction of the whole application. The data is stored and processed in other services. IoT Hub serves as a gathering point for all the devices and data. – rEsTrisA Jul 15 '19 at 01:26
  • Are the events consumed in your backend Web App require be processed in the order? – Roman Kiss Jul 15 '19 at 14:34
  • No, they aren't. It's important to process them fast but the order isn't. – rEsTrisA Jul 15 '19 at 15:45
  • 1
    OK, in this case, for comparation purpose of the latency time between the *Push-Pull* and *Push-Push* eventing, make a webhook handler in your Web App and subscribe to the *Azure Event Grid* for iothub topic with a filter on eventType = **Microsoft.Devices.DeviceTelemetry**. Note, that the IoT Hub firing (pushing) this event to the AEG during the routing step such as before its ingesting into the internal Event Hub, so this is very closed to the real-time and the AEG destination processing time can be ~1 ms. – Roman Kiss Jul 15 '19 at 18:01

2 Answers2

2

You can simply use the EventHub .NET SDK in your web app, connect to the EventHub-compatible endpoint of the IoT Hub and directly consume the events in your app. This has minimal delay and involves no extra components.

How to guide (.NET core but same applies to .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>();
silent
  • 8,986
  • 3
  • 23
  • 52
  • Thanks, that looks like the ideal solution. I will look into that and report back. – rEsTrisA Jul 15 '19 at 15:46
  • But do it in a Webjob, since running Web Apps as background workers leads straight to problems (most PaaS platforms suspend the app if there's no traffic hitting the public endpoint, something that would stop your processing altogether). – evilSnobu Jul 15 '19 at 17:53
  • Tested it with the command line application and it works like a charm. Now all that's left to do is to implement it into the ASP.NET app. I think running the EventProcessor in a Webjob should do the job so I consider my question answered. Thanks again! – rEsTrisA Jul 15 '19 at 17:54
0

The Azure SignalR Service can help to broadcast messages to the Web App instances.

There are no direct integration between the Azure IoT Hub and Azure SignalR Service. Basically you can use two patterns for this integration such as PULL-PUSH and PUSH-PUSH.

The following screen shows these integration patterns:

enter image description here

Note, that the PUSH-PUSH pattern with the Azure Event Grid is suitable for solution when the subscriber (consumer) is not critical for processing events in the order.

Roman Kiss
  • 6,378
  • 1
  • 5
  • 17
  • SignalR is really mostly to push content updates to the front end. The OP only mentions that he wants to get the data into the back end of his web app. Also, in terms of minimal delay, this introduces some extra layers, each of which adds some delay. – silent Jul 15 '19 at 08:05
  • @silent, you are right, he mentions only get the data into the azure back-end, so your answer for using the **EventProcessorHost** within the Web App is the way how to minimize a latency time for consuming an iot hub telemetry data. – Roman Kiss Jul 15 '19 at 11:56
  • The solution mentioned by silent looks like a more viable option for my problem but thanks for the input nevertheless. – rEsTrisA Jul 15 '19 at 15:49