0

I'd like top use MongoDB to handle my queue (instead of AWS SQS I use right now) and I'm going to follow http://www.mattinsler.com/why-and-how-i-replaced-amazon-sqs-with-mongodb/

In both cases (sqs and mongodb) I need a process with a while(true) that polls the queue. In my current configuration (.Net on the cloud) I have to pay for an additional worker role on Azure.

The idea/question is: would it be possible to install a simple js script server side on mongodb that while(true) polls queue (->check for new doc in the db) and fire an http post if found?

Are infinite loop as server side js on mongodb "allowed"? Any comments? Bonus? Malus?

Pietro
  • 751
  • 7
  • 22

1 Answers1

0

You can try using tailable cursor on capped collection. It has driver support in most languages :

http://www.mongodb.org/display/DOCS/Tailable+Cursors

( it works like tail -f done on a file, here tailing is done on a collection )

You can periodically restart your script, and get the data tailed for some interval. Also see : How to create tailable cursor in MongoDB shell?

Community
  • 1
  • 1
DhruvPathak
  • 42,059
  • 16
  • 116
  • 175
  • Thanks DhruvPathak I read both the links but I still have a doubt. The bonus to use tailable cursor is that if there's nothing to read it blocks for a while instead of returning empty, right? But the timeout is 4 seconds so this means that at the end of the story I have to poll at least every 4 seconds right? The question is, how can I write a while(true) loop in server side js? It's just a matter of: db.system.js.save( { _id : "foo" , value : function( x , y ){ while(true) { pause(4000); dosomething(x,y); } } } ); – Pietro Nov 01 '11 at 08:50