0

I have a webjob that gets triggered by queue messages. If the job gets too long, The message reappears on the queue and a new instance of the webjob is triggered consuming the same message. That is not meant to be.

How can set the timespan while a message is hidden on the queue before reappearing?

Cœur
  • 37,241
  • 25
  • 195
  • 267
BrilBroeder
  • 1,409
  • 3
  • 18
  • 37

1 Answers1

1

Azure Queue messages have a visibility timeout value (in seconds), which you can set programmatically at any time, prior to the message becoming visible again.

You haven't mentioned what language you're coding in, but from a raw REST API standpoint, you just need to do an update message operation (a PUT on the queue message). From the documentation:

https://myaccount.queue.core.windows.net/myqueue/messages/messageid?popreceipt=<string-value>&visibilitytimeout=<int-seconds>

Via .net (c#):

var message = queue.GetMessage();

queue.UpdateMessage(message,
    TimeSpan.FromSeconds(30),
    MessageUpdateFields.Visibility);

See here for the API call details.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • I am coding in c# and using the AzureSDK components. – BrilBroeder Oct 14 '16 at 16:20
  • Does this set the message to be invisible for 30 seconds whenever a triggered process grabs the message from the Q or makes it invisible now for the next 30 seconds ? – BrilBroeder Oct 14 '16 at 16:25
  • You call to set the timeout (say, 30 seconds) and it will now be invisible for 30 seconds, starting from the time you made the update call. Regardless of its past value. – David Makogon Oct 14 '16 at 16:29
  • I am rather looking for a way to set the timespan it is invisible if a webjob grabs it from the Q. That timespan can be set either upon putting the message on the Q or at the moment the webjob grabs it. – BrilBroeder Oct 14 '16 at 16:31