Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure IoT Hub, EventHub and Functions

I have an IoTHub with a route that points to an EventHub which triggers a Functions.

I'm having problem getting the DeviceId and other IoT Hub properties from the event object without adding those explicitly to the payload.

If I set the input type to a string (or a custom type):

public static void Run(string iotMessage, TraceWriter log) {
    log.Info($"C# Event Hub trigger function processed a message: {iotMessage}");
}

I only get the payload without any other IoT Hub properties like DeviceId, CorrelationId or MessageId.

I tried to set the type to EventData instead:

public static void Run(EventData iotMessage, TraceWriter log) {
    log.Info($"C# Event Hub trigger function processed a message: {JsonConvert.SerializeObject(iotMessage)}");
}

Now I can access the IoT Hub properties via two getters: Properties and SystemProperties. For example I can access DeviceId like this iotMessage.SystemProperties["iothub-connection-device-id"]. But it does not expose the payload.

So how do I access both IoT Hub properties and the payload?

like image 586
Kimmen Avatar asked Feb 02 '17 13:02

Kimmen


People also ask

What are the features of Azure IoT hub?

Azure IoT Hub provides a cloud-hosted solution back end to connect virtually any device. Extend your solution from the cloud to the edge with per-device authentication, built-in device management and scaled provisioning.

What is Eventhub in Azure?

Azure Event Hubs is a big data streaming platform and event ingestion service. It can receive and process millions of events per second. Data sent to an event hub can be transformed and stored by using any real-time analytics provider or batching/storage adapters.

What are the three components of an azure IoT hub message?

A message enrichment has three key elements, the key name for the enrichment, the value of the enrichment key, and the endpoints that the enrichment applies to. Message enrichments are added to the IoT Hub message as application properties.

What is difference between event grid and event hub?

Event hub is a managed service that helps ingest, process, and monitor events from any source so you can build dynamic data pipelines for real-time analytics. Event grid is a fully managed event routing service that allows you to easily publish and subscribe to events across your ecosystem.


1 Answers

That's the recommended way of doing this, if you need access to detailed event properties in addition to the payload. The simple/default bindings for string etc. are useful in cases where you don't need to access those event properties. Our runtime calls EventData.GetBytes() for you behind the scenes and converts the data to the input type you've specified.

I do think we could make improvements to facilitate these scenarios however. I've logged a bug here in our repo to track this.

like image 50
mathewc Avatar answered Sep 20 '22 06:09

mathewc