0.4.9 • Published 10 years ago
pushmq v0.4.9
pushmq
transparently handle push notifications across multiple services (apns,gcm), backed by a queue (rabbitmq, more to come).
Usage
Install via NPM
$ npm install pushmq
Example- Publisher
var pushmq = require('pushmq') ;
var config = require('./config') ;
var rabbit = new pushmq.transports.AMQP(config.rabbitmq) ;
var apns = new pushmq.services.APNS(config.apns) ;
var publisher = new pushmq.Publisher('apple_notifications',rabbit);
publisher.publish({ token : '2131324sdfgdsgdfg', payload : { foo : 'bar' } },function(){
console.log('published')
})
Example- Worker (simple)
var pushmq = require('pushmq') ;
var config = require('./config') ;
var rabbit = new pushmq.transports.AMQP(config.rabbitmq) ;
var apns = new pushmq.services.APNS(config.apns) ;
var worker = new pushmq.Worker('apple_notifications',rabbit,apns);
// start the worker and transparently process APNS messages over the rabbitmq transport
worker.init();
Example- Worker (advanced)
var pushmq = require('pushmq') ;
var config = require('./config') ;
var rabbit = new pushmq.transports.AMQP(config.rabbitmq) ;
var apns = new pushmq.services.APNS(config.apns) ;
var worker = new pushmq.Worker('apple_notifications',rabbit,apns);
// start the worker and pass in a function to handle notifications.
// Function receives 3 args (data,next,acknowledge). This allows you to
// 1) modify the data being pushed, or 2) short-circuit the notification.
// The 'next' function actually sends the push notification and takes
// two arguments ( data, acknowledge ). Messages must be acknowledged in
// order for the queue to be processed, so acknowledge must be passed as a
// callback to 'next'.
worker.init(function( d , next , acknowledge ){
console.log('Got a notification. About to push.\n',d) ;
// decide weather or not to continue with the push
if ( d.payload.type == 'foo' ) {
d.aps.alert = "FOO MESSAGE" ;
next( d , acknowledge ) ;
} else {
// disregard this notification and acknowledge without pushing
acknowledge() ;
}
});
// An additional queue will be created that contains tokens that
// have been rejected by the service provider. You can subscribe
// to this queue as well. Again, these messages must be acknowledged
// in order to run continuously.
worker.onInvalidDevice(function(d,acknowledge){
console.log('Got an invalid device identifier\n',d) ;
db.removeToken( d.token , function () {
acknowledge();
})
})
0.4.9
10 years ago
0.4.8
10 years ago
0.4.7
10 years ago
0.4.6
10 years ago
0.4.5
10 years ago
0.4.4
10 years ago
0.4.3
10 years ago
0.4.2
10 years ago
0.4.1
10 years ago
0.4.0
10 years ago
0.3.9
10 years ago
0.3.8
10 years ago
0.3.7
10 years ago
0.3.6
10 years ago
0.3.5
10 years ago
0.3.4
11 years ago
0.3.3
11 years ago
0.3.2
11 years ago
0.3.1
11 years ago
0.2.9
11 years ago
0.2.8
11 years ago
0.2.7
11 years ago
0.2.6
11 years ago
0.2.5
11 years ago
0.2.4
11 years ago
0.2.3
11 years ago
0.2.2
11 years ago
0.2.1
11 years ago
0.2.0
11 years ago
0.1.9
11 years ago
0.1.8
11 years ago
0.1.7
11 years ago
0.1.6
11 years ago
0.1.5
11 years ago
0.1.4
11 years ago
0.1.3
11 years ago
0.1.2
11 years ago
0.1.1
11 years ago
0.1.0
11 years ago
0.0.10
11 years ago
0.0.9
11 years ago
0.0.8
11 years ago
0.0.7
11 years ago
0.0.6
11 years ago
0.0.5
11 years ago
0.0.4
11 years ago
0.0.3
11 years ago
0.0.2
11 years ago
0.0.1
11 years ago