1

Used two different libraries for node.js, azure-storage and fast-azure-storage, to the same result.

Here's what I do:

  1. Create a message with default settings - ok.
  2. Get message from a queue - ok.
  3. Update message to reset visibility timeout - ok.
  4. Delete message after processing - Error: MessageNotFound.

If I skip updating, everything goes smooth.

So what I'm doing wrong?

P.S. Tried to analyse the http traffic, it seems to fully comply with the docs. Like this is an Azure internal problem? Maybe someone has any experience updating messages using other language libraries? Too inconvenient to curl that service due to calculation of the auth header.

Sergey B
  • 152
  • 2
  • 9

2 Answers2

1

As the document Delete Message mentions, the function requires the parameter popreceipt which is returned by Get Messages or Update Message operation.

And after update message operation, the popreceipt of this message changes. So if you code snippet looks like this:

queueSvc.getMessages('myqueue', function(error, result, response){
  if(!error){
    // Messages retreived
    for(var index in result){
      var message = result[0];
      queueSvc.updateMessage('myqueue', message.messageid, message.popreceipt, 0, {messageText: 'new text'}, function(error, result, response){
          if(!error){
            // Message updated successfully
            console.log('result: '+JSON.stringify(result));
            console.log(message.popreceipt)
            queueSvc.deleteMessage('myqueue', message.messageid, message.popreceipt, function(error, response){
                if(!error){
                    console.log(response);
                  // Message deleted
                }else{
                    console.log(error);
                }
              });
          }else{
            console.log(error);
          }
        });
    }
  }
});

You will occur your issue, and you can monitor in cmdlet, we found the popreceipt changed after update operation.

So if you need to delete the message after update operation, you have to leverage the result object which is the new message object after updating.E.g.

queueSvc.deleteMessage('myqueue', result.messageid, result.popreceipt, function(error, response){
            if(!error){
                console.log(response);
              // Message deleted
            }else{
                console.log(error);
            }
          });
Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Thanks, Gary! That was my guess. I was mislead by the `fast-azure-storage`, which ignores the new `popreceipt`. And the official module is really very slow with the queues. – Sergey B Nov 20 '15 at 07:45
  • Btw, it is already implemented in the `fast-azure-storage` module. – Sergey B Nov 25 '15 at 08:08
  • 1
    Yes, it seems the `updateMessage` function will return the new `popreceipt` from the [source code](https://github.com/taskcluster/fast-azure-storage/blob/master/lib/queue.js#L897) – Gary Liu Nov 27 '15 at 01:31
  • Yeah, actually that's there after my pull-request based on your answer here :) – Sergey B Nov 28 '15 at 04:54
0

What did you mean by "Update message to reset visibility timeout"? Did you set the invisibility timeout to zero? If so, the error in step 4 is expected because you're not allowed to delete the messages which are visible currently.

Zhaoxing Lu
  • 6,319
  • 18
  • 41