Skip to content

Instantly share code, notes, and snippets.

@derekcollison
Last active December 18, 2015 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekcollison/a6a40e009f33a032fc06 to your computer and use it in GitHub Desktop.
Save derekcollison/a6a40e009f33a032fc06 to your computer and use it in GitHub Desktop.
Many Subscriptions
#!/usr/bin/env node
/* jslint node: true */
'use strict';
var nats = require ('../lib/nats.js').connect('nats://demo.nats.io:4222');
var cuid = require('cuid');
nats.on('error', function(e) {
console.log('Error [' + nats.options.url + ']: ' + e);
process.exit();
});
nats.on('close', function() {
console.log('CLOSED');
process.exit();
});
nats.on('connect', function() {
var subs = 2000000;
var hash = 1000;
console.log('starting ' + subs + ' subscriptions');
for (var i=0; i<subs; i++) {
var sub = 'DEVICE.' + cuid() + '.OUT';
nats.subscribe(sub);
if (i % hash === 0) {
process.stdout.write('#');
}
}
nats.flush(function() {
console.log('\ndone')
console.log('<CTRL-C> to quit');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment