Azure, Azure IOTHub, Connected Field Service

Direct methods vs Cloud to Device messaging in Azure IOT Hub – When to use what?

Let’s see types of messages supported in Azure IOT Hub:

Cloud to Device messaging

Direct method

There are use cases for using each of these message types and one or the other isn’t  the solution for all problems.

Let’s see few of the differences between how these 2 methods work:

  • CDM uses One way messaging where as Direct method uses 2 way connection
  • Because of the above reason there is no easy feedback loop, there is a way to      leverage feedback endpoint in IOTHub but there is no way to relate feedback with message
  • CDM uses Hub to store the message and Hub is responsible of re-trying logic to send the message until expiration (configured at Hub level or can be configured for each device)
  • CDM Supports AMQP/ MQTT and HTTPS but Direct Methods don’t support HTTPS
Azure, Azure IOTHub, C#

Leveraging feedback endpoint in Azure IOT Hub

If you have played with Azure IOT Hub you might already know that there is an Azure Event hub endpoint behind the scene which takes care of message ingestion.

So your devices and backend applications use this endpoint for Cloud to device and Device to cloud communication.

In a scenario where the backend application wants to send a message to a Device and doesn’t care if the message was accepted/rejected or abandoned by the device then subscribing to the Event hub end point alone may do the trick.

But if you want feedback from IOT Hub that the message was indeed delivered and was it accepted or rejected you can subscribe to another already configured end point in Azure IOT hub which is the Feedback End point.

Let me show you the default endpoints configured in Azure IOT hub I just created:


If you see the above screenshot, there are 2 end points listed in IOT Hub:

  • Feedback
  • Events (Event Hub endpoint)

Now the next question is how to leverage this endpoint?

Fortunately Azure IOT Hub sdks have classes that take care of this, the class is called the FeedbackReceiver class and you can instantiate it using the ServiceClient object.

var feedbackReceiver = serviceClient.GetFeedbackReceiver();

Once you have the instance of this class, you can call the ReceiveAsyn() method to loop through the feedbacks to obtain the MessageId and the Status which could be one of the following:

  • Success
  • DeliveryCountExceeded
  • Expired
  • Rejected
  • Purged

Finally we can let the Hub know we are done processing feedbacks by calling the CompleteAsync() method.


As you see it’s not that hard to plug in the feedback loop for cloud to device messages 🙂



Azure, Azure IOTHub, Connected Field Service, Dynamics 365 Field Services, Logic Apps, Microsoft Dynamics 365

Get Device ConnectionString from IOTHub using LogicApp

As of today, there are 3 connectors to Azure IOT Hub:


I recently had a requirement to get the Device Connectionstring from IOTHub using DeviceId and IOT Hub connectionstring.

The solution comprised of following 2 items:

  1.  Custom connector to get Device Connectionstring
    1. This is a Web api deployed on Azure which has a Post method, takes in DeviceId and IOTHub connectionstring and returns Device Connectionstring using Azure IOTHub sdk.
    2.  HTTP + Swagger action was used in Logic app to consume this.
  2.  Logic app wrapper which was consumed by other apps.

If you want to use the Connector, consume the following swagger file:


Here’s the logic app definition: