Search code examples
c#messagingazure-iot-hubazure-function-app

Azure Function App - How to defer and re-receive an unprocessable message


I have the following Azure architecture:

IoTDevices ---> IoTHub ---> Function App

where:

  • IoTDevices: collect sensor data and send them to IoTHub
  • IoTHub: receives the data from devices and delivers those data to Function App (using Event Hub-compatible endpoint)
  • Function App: performs some processing on the received data

now in the Function App I have something like this:

public static void Run([IoTHubTrigger("messages/events", Connection = "EventHubConnection")]EventData message, TraceWriter log)
{
  string messageString = Encoding.UTF8.GetString(message.GetBytes());
  //do some processing with messageString as input
}

for several reasons, there are cases in which the processing can not be performed; I'd like to save the message SequenceNumber and defer the message so that later, when the processing become available again, I can re-receive the message from the IoTHub. So summarizing, the questions are:

  • how can I defer my message?
  • how can I re-receive/re-read the message given the SequenceNumber?

Solution

  • https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-deferral

    Deferred messages remain in the main queue along with all other active messages (unlike dead-letter messages that live in a subqueue), but they can no longer be received using the regular Receive/ReceiveAsync functions. Deferred messages can be discovered via message browsing if an application loses track of them.