Skip to content

Commit eb13450

Browse files
committed
Renamed QueueMgr class to Channel. Renamed WorkQueueBroker class to WorkQueueMgr.
Updated test and demo code to use the new class names. Hopefully, the new class names make better sense. The README.md file has been split up into several separate files to improve readability. No functionality has been changed since the previous version.
1 parent c063a87 commit eb13450

23 files changed

+321
-900
lines changed

README.md

+20-477
Large diffs are not rendered by default.

demo/lib/provider01.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/*
4-
QueueMgr Example -- provider01
4+
Channel Example -- provider01
55
66
For each URL in the urls list, this app pushes it into the 'urlq' queue
77
for consumption by worker01. When done with that, it quits.
@@ -18,30 +18,30 @@ Use this app in conjunction with worker01.js. See the worker01 source code
1818
for more details.
1919
*/
2020

21-
var QueueMgr, clearInitially, enqueueURLs, initEventHandlers, main, qmgr, stopWorker, urlQueueName, urls;
21+
var Channel, channel, clearInitially, enqueueURLs, initEventHandlers, main, stopWorker, urlQueueName, urls;
2222

23-
QueueMgr = require('node-redis-queue').QueueMgr;
23+
Channel = require('node-redis-queue').Channel;
2424

2525
urlQueueName = 'urlq';
2626

27-
qmgr = null;
27+
channel = null;
2828

2929
clearInitially = process.argv[2] === 'clear';
3030

3131
stopWorker = process.argv[2] === 'stop';
3232

3333
urls = ['http://www.google.com', 'http://www.yahoo.com', 'http://www.google.com/robots.txt', 'https://code.google.com'];
3434

35-
qmgr = new QueueMgr();
35+
channel = new Channel();
3636

37-
qmgr.connect(function() {
37+
channel.connect(function() {
3838
console.log('connected');
3939
initEventHandlers();
4040
return main();
4141
});
4242

4343
initEventHandlers = function() {
44-
return qmgr.on('end', function() {
44+
return channel.on('end', function() {
4545
console.log('provider01 finished');
4646
return process.exit();
4747
}).on('error', function(error) {
@@ -52,19 +52,19 @@ initEventHandlers = function() {
5252

5353
main = function() {
5454
if (clearInitially) {
55-
return qmgr.clear(urlQueueName, function() {
55+
return channel.clear(urlQueueName, function() {
5656
console.log('Cleared "' + urlQueueName + '"');
5757
enqueueURLs();
58-
return qmgr.disconnect();
58+
return channel.disconnect();
5959
});
6060
} else {
6161
if (!stopWorker) {
6262
enqueueURLs();
6363
} else {
6464
console.log('Stopping worker');
65-
qmgr.push(urlQueueName, '***stop***');
65+
channel.push(urlQueueName, '***stop***');
6666
}
67-
return qmgr.disconnect();
67+
return channel.disconnect();
6868
}
6969
};
7070

@@ -73,6 +73,6 @@ enqueueURLs = function() {
7373
for (_i = 0, _len = urls.length; _i < _len; _i++) {
7474
url = urls[_i];
7575
console.log('Pushing "' + url + '" to queue "' + urlQueueName + '"');
76-
qmgr.push(urlQueueName, url);
76+
channel.push(urlQueueName, url);
7777
}
7878
};

demo/lib/provider02.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/*
4-
QueueMgr Example -- provider02
4+
Channel Example -- provider02
55
66
For each URL in the urls list, this app puts a work request in 'urlq' queue
77
consumed by worker02 and waits for the results to be returned in 'urlshaq01'
@@ -29,9 +29,9 @@ Use this app in conjunction with worker02.js. See the worker02 source code
2929
for more details.
3030
*/
3131

32-
var QueueMgr, clearInitially, enqueueURLs, initEventHandlers, main, onData, providerId, qmgr, resultQueueName, resultsExpected, shutDown, stopWorker, urlQueueName, urls;
32+
var Channel, channel, clearInitially, enqueueURLs, initEventHandlers, main, onData, providerId, resultQueueName, resultsExpected, shutDown, stopWorker, urlQueueName, urls;
3333

34-
QueueMgr = require('node-redis-queue').QueueMgr;
34+
Channel = require('node-redis-queue').Channel;
3535

3636
urlQueueName = 'urlq';
3737

@@ -52,30 +52,30 @@ urls = ['http://www.google.com', 'http://www.yahoo.com', 'http://www.google.com/
5252

5353
resultsExpected = 0;
5454

55-
qmgr = new QueueMgr();
55+
channel = new Channel();
5656

57-
qmgr.connect(function() {
57+
channel.connect(function() {
5858
console.log('connected');
5959
initEventHandlers();
6060
return main();
6161
});
6262

6363
initEventHandlers = function() {
64-
qmgr.on('end', function() {
64+
channel.on('end', function() {
6565
console.log('provider01 finished');
6666
return shutDown();
6767
});
68-
return qmgr.on('error', function(error) {
68+
return channel.on('error', function(error) {
6969
console.log('provider01 stopping due to: ' + error);
7070
return shutDown();
7171
});
7272
};
7373

7474
main = function() {
7575
if (clearInitially) {
76-
return qmgr.clear(urlQueueName, function() {
76+
return channel.clear(urlQueueName, function() {
7777
console.log('Cleared "' + urlQueueName + '"');
78-
return qmgr.clear(resultQueueName, function() {
78+
return channel.clear(resultQueueName, function() {
7979
console.log('Cleared "' + resultQueueName + '"');
8080
return shutDown();
8181
});
@@ -85,7 +85,7 @@ main = function() {
8585
return enqueueURLs();
8686
} else {
8787
console.log('Stopping worker');
88-
qmgr.push(urlQueueName, '***stop***');
88+
channel.push(urlQueueName, '***stop***');
8989
return shutDown();
9090
}
9191
}
@@ -96,26 +96,26 @@ enqueueURLs = function() {
9696
for (_i = 0, _len = urls.length; _i < _len; _i++) {
9797
url = urls[_i];
9898
console.log('Pushing "' + url + '"');
99-
qmgr.push(urlQueueName, {
99+
channel.push(urlQueueName, {
100100
url: url,
101101
q: resultQueueName
102102
});
103103
++resultsExpected;
104104
}
105-
qmgr.pop(resultQueueName, onData);
105+
channel.pop(resultQueueName, onData);
106106
return console.log('waiting for responses from worker...');
107107
};
108108

109109
onData = function(result) {
110110
console.log('result = ', result);
111111
if (--resultsExpected) {
112-
return qmgr.pop(resultQueueName, onData);
112+
return channel.pop(resultQueueName, onData);
113113
} else {
114114
return shutDown();
115115
}
116116
};
117117

118118
shutDown = function() {
119-
qmgr.end();
119+
channel.end();
120120
return process.exit();
121121
};

demo/lib/provider03.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/*
4-
WorkQueueBroker Example -- provider03
4+
WorkQueueMgr Example -- provider03
55
66
For each string in the two expectedItems lists, this app sends it
77
into either 'work-queue-1' or 'work-queue-2' for consumption by worker03.
@@ -20,13 +20,13 @@ Use this app in conjunction with worker03.js. See the worker03 source code
2020
for more details.
2121
*/
2222

23-
var WorkQueueBroker, clear, clearWorkQueues, createWorkQueues, expectedItemsQ1, expectedItemsQ2, initEventHandlers, itemCntQ1, itemCntQ2, myBroker, myWorkQueue1, myWorkQueue2, sendData, sendStop, shutDown, stop, timesToRepeat;
23+
var WorkQueueMgr, clear, clearWorkQueues, createWorkQueues, expectedItemsQ1, expectedItemsQ2, initEventHandlers, itemCntQ1, itemCntQ2, mgr, queue1, queue2, sendData, sendStop, shutDown, stop, timesToRepeat;
2424

25-
myWorkQueue1 = null;
25+
queue1 = null;
2626

27-
myWorkQueue2 = null;
27+
queue2 = null;
2828

29-
myBroker = null;
29+
mgr = null;
3030

3131
expectedItemsQ1 = ['item one', 'item two', 'item three'];
3232

@@ -42,12 +42,12 @@ stop = process.argv[2] === 'stop';
4242

4343
timesToRepeat = parseInt(process.argv[2]) || 1;
4444

45-
WorkQueueBroker = require('node-redis-queue').WorkQueueBroker;
45+
WorkQueueMgr = require('node-redis-queue').WorkQueueMgr;
4646

47-
myBroker = new WorkQueueBroker();
47+
mgr = new WorkQueueMgr();
4848

49-
myBroker.connect(function() {
50-
console.log('work queue broker ready');
49+
mgr.connect(function() {
50+
console.log('work queue manager ready');
5151
initEventHandlers();
5252
createWorkQueues();
5353
if (stop) {
@@ -64,31 +64,31 @@ myBroker.connect(function() {
6464
});
6565

6666
initEventHandlers = function() {
67-
myBroker.on('error', function(error) {
67+
mgr.on('error', function(error) {
6868
console.log('>>>' + error);
6969
return shutDown();
7070
});
71-
return myBroker.on('end', function() {
71+
return mgr.on('end', function() {
7272
console.log('>>>End Redis connection');
7373
return shutDown();
7474
});
7575
};
7676

7777
createWorkQueues = function() {
78-
myWorkQueue1 = myBroker.createQueue('work-queue-1');
79-
myWorkQueue2 = myBroker.createQueue('work-queue-2');
78+
queue1 = mgr.createQueue('work-queue-1');
79+
queue2 = mgr.createQueue('work-queue-2');
8080
};
8181

8282
clearWorkQueues = function(done) {
8383
var queuesToClear;
8484
queuesToClear = 2;
85-
myWorkQueue1.clear(function() {
85+
queue1.clear(function() {
8686
console.log('Cleared "work-queue-1"');
8787
if (!--queuesToClear) {
8888
return done();
8989
}
9090
});
91-
return myWorkQueue2.clear(function() {
91+
return queue2.clear(function() {
9292
console.log('Cleared "work-queue-2"');
9393
if (!--queuesToClear) {
9494
return done();
@@ -102,22 +102,22 @@ sendData = function() {
102102
for (_i = 0, _len = expectedItemsQ1.length; _i < _len; _i++) {
103103
item = expectedItemsQ1[_i];
104104
console.log('publishing "' + item + '" to queue "work-queue-1"');
105-
myWorkQueue1.send(item);
105+
queue1.send(item);
106106
}
107107
for (_j = 0, _len1 = expectedItemsQ2.length; _j < _len1; _j++) {
108108
item = expectedItemsQ2[_j];
109109
console.log('publishing "' + item + '" to queue "work-queue-2"');
110-
myWorkQueue2.send(item);
110+
queue2.send(item);
111111
}
112112
}
113113
};
114114

115115
sendStop = function() {
116116
console.log('stopping worker03');
117-
myWorkQueue1.send('***stop***');
118-
return myWorkQueue2.send('***stop***');
117+
queue1.send('***stop***');
118+
return queue2.send('***stop***');
119119
};
120120

121121
shutDown = function() {
122-
return myBroker.shutdownSoon();
122+
return mgr.shutdownSoon();
123123
};

demo/lib/provider04.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/*
4-
WorkQueueBroker Example -- provider04
4+
WorkQueueMgr Example -- provider04
55
66
For each URL in the urls list, this app puts a work request in 'urlq' queue to be
77
consumed by worker04. It then waits for the results to be returned in 'urlshaq01'
@@ -29,9 +29,9 @@ Use this app in conjunction with worker02.js. See the worker02 source code
2929
for more details.
3030
*/
3131

32-
var WorkQueueBroker, clearInitially, clearQueues, consumeResultQueue, createWorkQueues, initEventHandlers, myBroker, providerId, resultQueue, resultQueueName, resultQueueTimeout, resultsExpected, sendURLs, stopOneWorker, stopWorker, urlQueue, urlQueueName, urls;
32+
var WorkQueueMgr, clearInitially, clearQueues, consumeResultQueue, createWorkQueues, initEventHandlers, mgr, providerId, resultQueue, resultQueueName, resultQueueTimeout, resultsExpected, sendURLs, stopOneWorker, stopWorker, urlQueue, urlQueueName, urls;
3333

34-
WorkQueueBroker = require('node-redis-queue').WorkQueueBroker;
34+
WorkQueueMgr = require('node-redis-queue').WorkQueueMgr;
3535

3636
urlQueueName = 'urlq';
3737

@@ -58,9 +58,9 @@ urls = ['http://www.google.com', 'http://www.yahoo.com', 'http://www.google.com/
5858

5959
resultsExpected = 0;
6060

61-
myBroker = new WorkQueueBroker();
61+
mgr = new WorkQueueMgr();
6262

63-
myBroker.connect(function() {
63+
mgr.connect(function() {
6464
console.log('connected');
6565
initEventHandlers();
6666
createWorkQueues();
@@ -75,27 +75,27 @@ myBroker.connect(function() {
7575
});
7676

7777
initEventHandlers = function() {
78-
myBroker.on('end', function() {
78+
mgr.on('end', function() {
7979
console.log('provider04 finished');
8080
return process.exit();
8181
});
82-
return myBroker.on('error', function(error) {
82+
return mgr.on('error', function(error) {
8383
console.log('provider01 stopping due to: ' + error);
8484
return process.exit();
8585
});
8686
};
8787

8888
createWorkQueues = function() {
89-
urlQueue = myBroker.createQueue(urlQueueName);
90-
resultQueue = myBroker.createQueue(resultQueueName);
89+
urlQueue = mgr.createQueue(urlQueueName);
90+
resultQueue = mgr.createQueue(resultQueueName);
9191
};
9292

9393
clearQueues = function() {
9494
return urlQueue.clear(function() {
9595
console.log('cleared "' + urlQueueName + '"');
9696
return resultQueue.clear(function() {
9797
console.log('cleared "' + resultQueueName + '"');
98-
return myBroker.disconnect();
98+
return mgr.disconnect();
9999
});
100100
});
101101
};
@@ -121,13 +121,13 @@ consumeResultQueue = function() {
121121
console.log('result = ', result);
122122
ack();
123123
if (!--resultsExpected) {
124-
return myBroker.end();
124+
return mgr.end();
125125
}
126126
});
127127
};
128128

129129
stopOneWorker = function() {
130130
console.log('Stopping worker');
131131
urlQueue.send('***stop***');
132-
return myBroker.disconnect();
132+
return mgr.disconnect();
133133
};

0 commit comments

Comments
 (0)