8000 Provided an example for priority queue implementation · girirajsharma/rabbitmq-tutorials@e9f6143 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9f6143

Browse files
author
Giriraj Sharma
committed
Provided an example for priority queue implementation
1 parent 4a7dfa8 commit e9f6143

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
3+
var amqp = require('amqplib/callback_api');
4+
5+
amqp.connect('amqp://localhost', function(err, conn) {
6+
conn.createChannel(function(err, ch) {
7+
var q = 'hello';
8+
9+
ch.assertQueue(q, {durable: false, maxPriority: 10});
10+
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
11+
ch.consume(q, function(msg) {
12+
console.log(" [x] Received %s", msg.content.toString());
13+
}, {noAck: true});
14+
});
15+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env node
2+
3+
var amqp = require('amqplib/callback_api');
4+
5+
amqp.connect('amqp://localhost', function(err, conn) {
6+
conn.createChannel(function(err, ch) {
7+
var q = 'hello';
8+
9+
ch.assertQueue(q, {durable: false, maxPriority: 10});
10+
for(var index=1; index<=50; index++) {
11+
priorityValue = Math.floor((Math.random() * 10));
12+
// index refers to message number. Lower is the index value, earlier is the message pushed into the queue.
13+
message = 'Message index = ' + index + ' and Priority Value = ' + priorityValue;
14+
ch.sendToQueue(q, new Buffer(message), {priority: priorityValue});
15+
console.log(" [x] Sent '%s'", message);
16+
}
17+
});
18+
setTimeout(function() { conn.close(); process.exit(0) }< 37F0 span class=pl-kos>, 500);
19+
});

0 commit comments

Comments
 (0)
0