ux4iot
Search…
Using a separate Event Hub
In addition to the built-in Event Hub of your IoT Hub you can use a separate Event Hub as well.

Scenario 1

An Event Hub receives messages from IoT Hub through message routing or via an Azure Function transformation.
Messages transformed by Azure Functions and written to Event Hub

Scenario 2

It's also possible that you do not use an IoT Hub at all, but send messages to the Event Hub by other means. For example when devices communicate via a legacy protocol not supported by IoT Hub. There is a custom protocol endpoint, e.g. realized using an Azure Function, that the devices connect to.
Custom Protocol Adapter

Scenario 3

Data is received not from devices directly but via some other cloud.
Data forwarded from other cloud

Using ux4iot with Event Hubs

In Scenario 1 all hooks can be used. You only need to configure ux4iot with the connection string of the Event Hub instead of the connection string of the Event Hub compatible endpoint of IoT Hub. In scenario 2 and 3, which do not include an IoT Hub at all, the following hooks can be used:
When you send messages to Event Hub, they must adhere to the following requirements:
  • They must have a property iothub-connection-device-id containing the device identifier
  • They must have a property iothub-message-schema. The value of this property must be Telemetry.
  • You can optionally set the timestamp of the data with the iothub-creation-time-utc property. The value must be in ISO 8601 format, e.g. "2022-01-01T12:00:00.000Z". If it is not set, the current server timestamp is used instead.
If you send the messages from IoT Hub through message routing, these properties are automatically set.
Here is an example of sending a message to an Event Hub using Node.js:
1
const { EventHubProducerClient } = require("@azure/event-hubs");
2
3
const eventHubName = "ux4iot-input";
4
5
const {
6
EVENT_HUB_CONNECTION_STRING
7
} = process.env;
8
9
function getRandomInt(max) {
10
return Math.floor(Math.random() * Math.floor(max));
11
}
12
13
async function main() {
14
15
// Create a producer client to send messages to the event hub.
16
const producer = new EventHubProducerClient(EVENT_HUB_CONNECTION_STRING, eventHubName);
17
18
const now = new Date();
19
20
const body = {
21
temperature: 42.1,
22
pressure: 10.9,
23
24
};
25
26
const properties = {
27
"iothub-connection-device-id": "some-device",
28
"iothub-message-schema": "Telemetry",
29
"iothub-creation-time-utc": now.toISOString()
30
};
31
32
const batch = await producer.createBatch();
33
batch.tryAdd({ body, properties });
34
35
await producer.sendBatch(batch);
36
await producer.close();
37
}
38
39
main().catch((err) => {
40
console.log("An error occurred: ", err);
41
})
Copied!