Krister Johansson Krister Johansson - 2 years ago 367
Node.js Question

Azure ioT and Event Hub?

I am trying to read the events that my device is sending. I am using azure npm lib to read the what i think is right.

Ok so first, under my Azure ioT Hub account for that service there is a tab call Messaging. There is something called "Event Hub-compatible name" and "Event Hub-compativle endpoint". Do i have to create a new Event hub with the name of "Event Hub-compatible name" or what? I am a bit confused :D
If not what is the connection string and topic and so on?

Here is how the code is now...

var azure = require('azure');

var serviceBusService = azure.createServiceBusService("");
var isWaiting = false;

function waitForMessages(){
console.log("Checking Queue...");
isWaiting = true;
serviceBusService.receiveQueueMessage("messages","events",function (error, receivedMessage){
isWaiting = false;

// Start messages listener
setInterval(function () {
}, 200);

Answer Source

The Event Hub-compatible name does not mean that you have to create a Event Hub with the same name.

IOT Hub provides an endpoint that is backward compatible with Event Hub API. I think the actual implementation is a little more complex, but you can think of IOT Hub as inheriting from or at least an implementation of Event Hubs. Use this Event Hub compatible name with any Event Hub SDKs or code examples as part of the connection string.

For explaining the concepts of Event Hub-compatible name & Event Hub-compatible endpoint, you can refer to the section How to read from Event Hubs-compatible endpoints of the offical doc Azure IoT Hub developer guide. You can use the Azure Service Bus SDK for .NET or the Event Hubs - Event Processor Host to read events from IoT Hub in C#.

Otherwise, there are two Azure IoT SDKs for NodeJS using connection string: Azure IoT Service SDK (API Reference) & Azure IoT Device SDK (API Reference).

The connection string that you can find it at the one policy of the tab Shared Access Policies in the All settings, please see the pic below from the doc Tutorial: Get started with Azure IoT Hub.

enter image description here

According to your needs for reading events from IoT Hub, you can follow these samples to code using Azure IoT SDKs for NodeJS.

  1. Using Azure IoT Service SDK to list the deviceIds registed in your IoT Hub, please see the sample
  2. Using Azure IoT Device SDK to monitor events from IoT Hub, please see the sample

Hope it helps. Any concern, please feel free to let me know.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download