-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish.js
38 lines (32 loc) · 852 Bytes
/
publish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var Crypto = require("crypto");
var NSQClient = require("../index");
var Util = require("util");
var client = new NSQClient({
debug: true
});
client.on("error", function(err) {
console.log("ERROR " + Util.inspect(err));
});
client.on("debug", function(event) {
console.log("DEBUG " + Util.inspect(event));
});
var topics = process.argv.slice(2);
function randomishTopic() {
var i = Math.floor(Math.random() * topics.length);
return topics[i];
}
setInterval(function() {
client.publish(randomishTopic(), {
date: Date.now(),
meh: Crypto.randomBytes(8).toString("hex")
});
}, 50);
process.once("SIGINT", function() {
process.once("SIGINT", process.exit);
console.log();
console.log("Closing client connections");
console.log("Press CTL-C again to force quit");
client.close(function() {
process.exit();
});
});