File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments