Chanki
Chanki

Reputation: 165

The remote server returned an error: (404) Not Found While deleting message from queue

We are using Azure Queue for our printing job but when deleting message from queue by queue.DeleteMessage(message), the method throws below exception.

The remote server returned an error: (404) Not Found

Above exception was handled but still looking for workaround.

Can anyone please suggest how to fix it.

Thanks, Sneh

Upvotes: 1

Views: 1974

Answers (2)

Morgan Kenyon
Morgan Kenyon

Reputation: 3172

I ran into this issue today and the root cause was ownership issues between two different queues. We had setup two queues, one to hold our message awaiting processing and one for messages that had errored out. The problem came with the logic of how the message was moved between queues.

If our processing failed, we would perform the following logic:

_errorQueue.AddMessage(msg);
_queue.DeleteMessage(msg);

The DeleteMessage would also return a (404) Not Found because the msg had been moved to the errorQueue. There were two solutions that I found to this issue:

1. Switch Logic

If you switch the logic than the msg will be deleted before being added to the errorQueue which will avoid the ownership swap.

_queue.DeleteMessage(msg);
_errorQueue.AddMessage(msg);

2. Insert Copy of Message

Solution #1 has the potential to lose the message if something happens between deletion and insertion (small chance but a chance nonetheless). The solution I went with inserted a copy of the msg with the same payload so it didn't run into this ownership issue because it was a different object.

_errorQueue.AddMessage(new CloudQueueMessage(msg.AsString));
_queue.DeleteMessage(msg);

Debugging Tip

One useful tip I encountered while debugging it making sure the exception your catching isn't the default Exception. Catch the StorageException instead to get access to Azure Storage related error information.

try
{
    _queue.DeleteMessage(msg);
}
catch (StorageException ex) //use this instead of base Exception
{
    var info = ex.RequestInformation; //has useful information
}

If can provide more information to help you debug your real issue.

Upvotes: 1

Fei Han
Fei Han

Reputation: 27793

According to this article, we can find that:

After a client retrieves a message with the Get Messages operation, the client is expected to process and delete the message. To delete the message, you must have two items of data returned in the response body of the Get Messages operation:

  • The message ID, an opaque GUID value that identifies the message in the queue.
  • A valid pop receipt, an opaque value that indicates that the message has been retrieved.

If a message with a matching pop receipt is not found, the service returns error code 404 (Not Found). And Pop receipts remain valid until one of the following events occurs:

  1. The message has expired.
  2. The message has been deleted using the last pop receipt received either from Get Messages or Update Message.
  3. The invisibility timeout has elapsed and the message has been dequeued by a Get Messages request. When the invisibility timeout elapses, the message becomes visible again. If it is retrieved by another Get Messages request, the returned pop receipt can be used to delete or update the message.
  4. The message has been updated with a new visibility timeout. When the message is updated, a new pop receipt will be returned.

Upvotes: 1

Related Questions