Is it possible to send MQTT message to Event Hub? Or is there another way?
Asked Answered
L

4

6

I am new with Azure, MQTT, and IoT. I have been given a task to create a POC on how to send MQTT message to Azure Event Hub.

And from the Event Hub processing, save the message to cloud sql server.

Is this possible? Since i read from here, that Azure Event Hub does not support MQTT. Or is there a workaround for this? Or is there a better way to do this?

Currently i am trying to research Azure Event Hub and Azure IoT hub.

Please help me. Thank you.

Labored answered 17/5, 2019 at 3:29 Comment(0)
J
7

Azure Event Hub does not support MQTT, only Azure IoT Hub does. See here for details, also how to send MQTT messages with or without the Microsoft SDKS: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support

Once you send messages into IoT Hub, you can consume them on the Event Hub-compatible endpoint of the IoT Hub. Or, if you need the data in a "real" Event Hub, you can use routing to forward the messages from the IoT Hub into an Event Hub.

Jackass answered 17/5, 2019 at 7:18 Comment(1)
Actually Azure IoTHub does NOT support MQTT but only a subset of it. The documentation states: "IoT Hub is not a full-featured MQTT broker and does not support all the behaviors specified in the MQTT v3.1.1 standard." You can learn more about the limitations here: learn.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-supportExeat
Z
2

I am doing somewhat the same thing in my project and I found a way to do so.

As already the other answers have mentioned that you can send MQTT message to IoT Hub and then to EventHub, the process would be, use Azure IoT SDK for developing application for IoT device and send your messages using MQTT protocol to IoT Hub. You can use Device Provisioning Service here if you want to connect your IoT device automatically to IoT Hub, in this case you will have to give the DPS connection information in the application code so that device will communicate to DPS and get the IoT hub connection information. You can look for the documentation for that https://learn.microsoft.com/en-us/azure/iot-dps/about-iot-dps

If you want, you can create Kafka enabled Event Hub instance and then create topic/event hub in it. Now you can route all your IoT Hub messages to this topic. The advantage is now you can build an application such as dashboard that shows IoT device's generated data, and the data source for that will be this Kafka enabled Event Hub service. You can see one example in the documentation https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-quickstart-kafka-enabled-event-hubs

Zingaro answered 17/5, 2019 at 8:28 Comment(0)
F
0

You can send your MQTT messages to an IotHub. The IotHub has a default endpoint compatible to EventHubs. Next you could create an AzureFunction with an EventHubTrigger to process the messages. Within that function you can extract the data from your messages and save it to an SQL Database.

Alternatively you can use StreamAnalytics to save the messages received by IotHub to your database. StreamAnalytics is more costly though than using an AzureFunction.

Ferritin answered 17/5, 2019 at 7:20 Comment(0)
I
-1

Azure Function EventHub Trigger is a quick solution to your question. Originally IoT Hub and Event Hub are more client concentric and machine to machine concentric respectively. Once you want to connect thousands of device in scale you have to use the IoTHub and provide the event processing loads to the back-end's Event-Hub layer. Here are the features of IoTHub and EventHub

So the simplest way to gain mqtt messages from device to EventHub is to leverage IoTHub and employ an Azure Function comprises of Event-Hub Trigger to get the EventData. Finally Injest that EventData to Azure SQL Server.

You can access the IoTHub MQTT directly using sdk or azure iothub API, otherwise using an MQTT Broker as a Bridge to IoTHub.

As first step try to use curl command to directly access Azure IoTHub API.

Publish Example

mosquitto_pub -d -q 1 --capath /etc/ssl/certs/ -V mqttv311 -p 8883 \
  -h iothub007.azure-devices.net \
  -i device0001 \
  -u "iothub007.azure-devices.net/device0001/api-version=2016-11-14" \
  -P "SharedAccessSignature sr=xxxx&skn=xxxx&sig=xxxx&se=xxxx" \
  -t "devices/device0001/messages/events/"
  -m '{"message":"howdy"}'

Subscribe Example

mosquitto_sub -d -q 1 --capath /etc/ssl/certs/ -V mqttv311 -p 8883 \
  -h iothub0007.azure-devices.net \
  -i device0001 \
  -u "iothub0007.azure-devices.net/device0001/api-version=2016-11-14" \
  -P "SharedAccessSignature sr=xxxx&skn=xxxx&sig=xxxx&se=xxxx" \
  -t "devices/device0001/messages/devicebound/#"

In Second Phase

You can try to use Azure IoT SDK to do the same as above.

If the second step seems hard then try to use MQTT broker as a bridge to the Azure IoT Hub(*). I would recommend to use VerneMQ or Mosquitto.

Currently MS Azure IoT SDK support all MQTT, AMQP, HTTP from SDK.

Reference Codes: github

Ignominy answered 20/5, 2019 at 5:58 Comment(4)
That statement is wrong: "Currently MS Azure IoT SDK do not support MQTT directly(AMQP is supported from SDK) , that is why its be quick to use an MQTT broker MQTT bridge." Using the SDKs you can chose between MQTT, AMQP or HTTPSJackass
Its true for official C# sdk for Azure IoT. Amqp still not officially supported.Ignominy
What's your source for this? And now you said AMQP is not supported - before you said MQTT is not?!Jackass
sorry, my bad, c# sdk support all MQTT, AMQP, HTTP.Ignominy

© 2022 - 2024 — McMap. All rights reserved.