Pergunta

How can I set the TTL for messages I put in the Azure queue, such that they don't last beyond 30 seconds using Node.js?

I can't seem to find any mention of Time To Live in the SDK for Node.js on Github.

Foi útil?

Solução

If you look at the documentation for createMessage on Github (https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/queue/queueservice.js), you'll notice that you can provide additional parameters to that operation. One of the parameter is messagettl. You would need to specify that parameter. See sample code below. Here the message will automatically expire after 30 seconds.

var azure = require('azure');
var queueService = azure.createQueueService("account", "key");
queueService.createQueueIfNotExists("dummy", function(error){
    if(!error){
        queueService.createMessage("dummy", "Hello world!", {messagettl: 30}, function(error){
    if(!error){
        console.log("Message Created");
    }
});
    }
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top