Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-queue

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-queue - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

7

mongodb-queue.js

@@ -79,3 +79,8 @@ /**

if (err) return callback(err)
callback(null, { id : msg.id, ack : msg.ack, payload : msg.payload })
callback(null, {
id : msg.id,
ack : msg.ack,
payload : msg.payload,
tries : msg.tries,
})
})

@@ -82,0 +87,0 @@ }

2

package.json
{
"name": "mongodb-queue",
"version": "0.1.0",
"version": "0.2.0",
"description": "Message queues which uses MongoDB.",

@@ -5,0 +5,0 @@ "main": "mongodb-queue.js",

# mongodb-queue #
[![Build Status](https://travis-ci.org/chilts/mongodb-queue.png)](https://travis-ci.org/chilts/mongodb-queue) [![NPM](https://nodei.co/npm/mongodb-queue.png?mini=true)](https://nodei.co/npm/mongodb-queue/)
## Synopsis ##
Create a connection to MongoDB to create a queue object:
Create a connection to your MongoDB database, and use it to create a queue object:
```js
var mongodb = require('mongodb')
mongodb.MongoClient.connect(conStr, function(err, db) {
var con = 'mongodb://localhost:27017/test'
mongodb.MongoClient.connect(con, function(err, db) {
var queue = Queue(db, 'my-queue')

@@ -46,7 +49,7 @@ })

This is the name of the collection you wish to use. Note: we only use one
collection for each queue instantiated. In fact, you can use the same collection
for multiple queues.
This is the name of the MongoDB Collection you wish to use to store the messages.
By default we only use this one MongoDB Collection, unless you specify an
alternate one.
e.g. both of these queue use the same `'msgs'` collection:
e.g. both of these queues use the same `'msgs'` collection by default:

@@ -58,3 +61,3 @@ ```

e.g. these both use the `'app'` collection:
e.g. both of these queue use the MongoDB Collection named `'app'`:

@@ -66,3 +69,3 @@ ```

e.g. these use both the `'msgs'` and `'app'` collections:
e.g. these two queue use different MongoDB Collections, `'msgs'` and `'app'` respectively:

@@ -74,4 +77,4 @@ ```

It shouldn't be a problem if you generally use the same MongoDB Collection
however you may wish to change this if you have high throughput.
Using the default MongoDB Collection for all of your queues shouldn't cause a problem
but you may wish to use a different collection per queue if you have a high throughput.

@@ -93,4 +96,35 @@ ### Message Visibility Window ###

All messages in this queue now have a visibility window of 15s.
All messages in this queue now have a visibility window of 15s, instead of the
default 30s.
## Use of MongoDB ##
Whilst using MongoDB recently and having a need for lightweight queues, I realised
that the atomic operations that MongoDB provides are ideal for this kind of job.
Since everything it atomic, it is impossible to lose messages in or around your
application. I guess MongoDB could lose them but it's a safer bet it won't compared
to your own application.
As an example of the atomic nature being used, messages stay in the same collection
and are never moved around or deleted, just a couple of fields are set, incremented
or deleted. We always use MongoDB's excellent `collection.findAndModify()` so that
each message is updated atomically inside MongoDB and we never have to fetch something,
change it and store it back.
## Releases ##
### 0.2.0 (2014-03-18) ###
* [NEW] messages now return number of tries (times they have been fetched)
### 0.1.0 (2014-03-18) ###
* [NEW] add messages to queues
* [NEW] fetch messages from queues
* [NEW] ack messages on queues
* [NEW] set up multiple queues
* [NEW] set your own MongoDB Collection name
* [NEW] set a visibility timeout on a queue
## Author ##

@@ -97,0 +131,0 @@

@@ -7,3 +7,3 @@ var mongodb = require('mongodb')

var conStr = 'mongodb://localhost:27017/msgs'
var conStr = 'mongodb://localhost:27017/mongodb-queue'

@@ -39,3 +39,8 @@ test('first test', function(t) {

t.ok(msg.id, 'Got a msg.id')
t.equal(typeof msg.id, 'string', 'msg.id is a string')
t.ok(msg.ack, 'Got a msg.ack')
t.equal(typeof msg.ack, 'string', 'msg.ack is a string')
t.ok(msg.tries, 'Got a msg.tries')
t.equal(typeof msg.tries, 'number', 'msg.tries is a number')
t.equal(msg.tries, 1, 'msg.tries is currently one')
t.equal(msg.payload, 'Hello, World!', 'Payload is correct')

@@ -42,0 +47,0 @@ next()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc