2

How can I keep a message in the "function App" until I decide to remove it?

When I build a console app in c#, I can decide when I remove the message that I read with:

queue.DeleteMessage(msg);

I'm able to read the queue automatically with this procedure: functions-create-storage-queue-triggered-function.

The problem is, like Azure said:

  1. Back in Storage Explorer, click Refresh and verify that the message has been processed and is no longer in the queue.

In this context, I can't remove the message by myself when the function is done.

I tried to Throw new Exception("failed"); to simulate a failed function but the message is removed anyway.

I'm looking to keep this message in queue until I decide to remove it (At the end of the function).

Jean-philippe Emond
  • 1,619
  • 2
  • 17
  • 29

1 Answers1

6

I tried to Throw new Exception("failed"); to simulate a failed function but the message is removed anyway.

The message isn't removed, it goes invisible for whatever the visibility-timeout is in seconds. You are running your code in the context of the WebJobs SDK, that's why you can't call .DeleteMessage() on your own. You are only being handed the message, not the queue client.

If your Function completes successfully, then the message will be removed by the Functions runtime (WebJobs SDK).

Ref:
https://stackoverflow.com/a/40011705/4148708
https://github.com/Azure/azure-webjobs-sdk/issues/1040

EDIT: Dequeue count can also bite. WebJobs SDK will move the message to the poison queue (QueueName-poison) if the message dequeueCount property reaches 5.

See this for more:
https://github.com/Microsoft/azure-docs/blob/master/articles/app-service-web/websites-dotnet-webjobs-sdk-storage-queues-how-to.md#automatic-poison-message-handling

evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • True, I tried a success message and 1 with the "throw" and the success message works and disappear but the failed message is in the `myqueue-poison`. But `NextVisibleTime="Null"` – Jean-philippe Emond May 24 '17 at 15:34
  • 1
    It means that it has been dequeued 5 times already, the SDK will move it to the poison queue if the `dequeueCount` property reaches 5. I think it's 5, don't quote me on that, check the docs. – evilSnobu May 24 '17 at 15:46
  • 1
    Yes, it's 5. You can quote me :) --https://github.com/Microsoft/azure-docs/blob/master/articles/app-service-web/websites-dotnet-webjobs-sdk-storage-queues-how-to.md#automatic-poison-message-handling – evilSnobu May 24 '17 at 15:49