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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
;(function(){
const http = require("http");
const log = process.stderr;
const out = process.stdout;
const NOOP = function(){};
setTimeout(main); return;
function main(){
const app = Object.seal({
isHelp: false,
host: "localhost",
port: 7013,
uri: "/houston/tmp/gugus/bar",
queueName: "my-gaga-queue",
});
if( parseArgs(app, process.argv) !== 0 ) process.exit(1);
if( app.isHelp ){ printHelp(); return; }
run(app);
}
function printHelp(){
out.write("\n"
+" Produce a bunch of gateleen queues\n"
+" \n"
+" Options:\n"
+" \n"
+" \n")
}
function parseArgs( app, argv ){
var isYolo = false;
for( var iA = 2 ; iA < argv.length ; ++iA ){
var arg = argv[iA];
if( arg == "--help" ){
app.isHelp = true; return 0;
}else if( arg == "--yolo" ){
isYolo = true;
}else{
log.write("EINVAL: "+ arg +"\n");
return -1;
}
}
if( !isYolo ){ log.write("EINVAL: wanna yolo?\n"); return; }
return 0;
}
function run( app ){
//placeHook(app);
putSomeNonsense(app);
}
function placeHook( app ){
const req = Object.seal({
base: null,
app: app,
});
req.base = http.request({
host: app.host, port: app.port,
method: "PUT", path: app.uri +"/_hooks/listeners/http",
//headers: {
// "X-Expire-After": "42",
//},
});
req.base.on("response", onResponse.bind(0, req));
req.base.end(JSON.stringify({
destination: "http://127.0.0.1:7099/guguseli",
queueExpireAfter/*seconds*/: 42,
}));
function onResponse( req, rsp ){
var app = req.app;
log.write("[DEBUG] < HTTP/"+ rsp.httpVersion +" "+ rsp.statusCode +" "+ rsp.statusMessage +"\n");
for( var k of Object.keys(rsp.headers) ) log.write("[DEBUG] < "+ k +": "+ rsp.headers[k] +"\n");
}
}
function putSomeNonsense( app ){
const nonsense = Object.seal({
app: app,
req: null,
i: 0,
limit: 42,
});
putNextRequest(nonsense);
function putNextRequest( nonsense ){
nonsense.req = http.request({
host: app.host, port: app.port,
method: "PUT", path: app.uri +"/foo/"+ nonsense.i,
headers: {
"X-Queue": app.queueName +"-"+ nonsense.i,
"X-Queue-Expire-After": 9999999,
},
});
nonsense.req.on("response", onResponse.bind(0, nonsense));
nonsense.req.end("{\"guguseli\":\""+ new Date().toISOString() +"\"}\n");
}
function onResponse( nonsense, rsp ){
var app = nonsense.app;
log.write("[DEBUG] < HTTP/"+ rsp.httpVersion +" "+ rsp.statusCode +" "+ rsp.statusMessage +"\n");
for( var k of Object.keys(rsp.headers) ) log.write("[DEBUG] < "+ k +": "+ rsp.headers[k] +"\n");
rsp.on("data", NOOP);
if( nonsense.i++ < nonsense.limit ){
putNextRequest(nonsense);
}
}
}
}());
|