1

I have several Azure Functions with Queue Triggers. In Version 2

public static void Run(string message, ICollector<string> output, ILogger log) {
  try { DoMyFunction(message, output, log); }
  catch { // HOWTO: Tell Queue Not to Bother Retrying }
}

All onwards Queues are as output collections.

Given a Message that is not supported
When then message is processed by my function
Then my function should return a status that ensures the message is not retried

I am assuming that an HTTP 400 Bad Request is what we're after - therefore I'm looking for the equivalent of

public static HttpStatusCode Run(string message, ICollector<string> output, ILogger log)
{
  try {
    DoMyFunction(message, output, log);
    return HttpStatusCode.OK;
  }
  catch { return HttpStatusCode.BadRequest; }
}
David Lapeš
  • 342
  • 2
  • 9
  • From your description I am not sure what your intent is. Maybe this is a solution for you https://stackoverflow.com/questions/44786141/how-do-i-define-retry-count-and-internal-for-azure-function – Sebastian Achatz Nov 15 '18 at 14:26
  • No - This is a response to one specific message only. If the message is invalid - please don't try again. It may be that legal messages fail halfway through and need to be retried. – David Lapeš Nov 15 '18 at 17:23
  • @DavidLapeš, where would you be returning the HTTP status code in this case? what is your output supposed to be? Note that you can only return an HTTP response to an HTTP request – Marie Hoeger Nov 16 '18 at 00:46
  • This is to signal to the ServiceBus that the message is unsupported and should be deadlettered – David Lapeš Nov 16 '18 at 14:00

2 Answers2

1

If I understand correctly, you should configure you function in host.json and set maxDequeueCount to 1.

Nick
  • 4,787
  • 2
  • 18
  • 24
1

The messageHandlerOptions in host.json for Service Bus will be useful to you (specifically, autoComplete). Instead of returning an HTTP response, which doesn't make sense in the context of Azure Functions bindings, you can use methods on BrokeredMessage. This stackoverflow post may be helpful, although note that the answer is out of date.

When looking for documentation no this, you should look for information about the Service Bus binding and not "Queue storage" or "Queue Trigger", as these bindings are for Azure Storage queues.

Marie Hoeger
  • 1,261
  • 9
  • 11
  • This is useful - but I will need to change the implementation in all my other functions to take control of completion. It would be useful to have this as an attribute on the entry point or binding. – David Lapeš Nov 20 '18 at 09:47