File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " rabbitmq-node-tutorial" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " RabbitMQ amqp.node tutorial " ,
5
+ "dependencies" : {
6
+ "amqplib" : " ^0.3.2" ,
7
+ "when" : " ^3.6.4"
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ var amqp = require ( 'amqplib' ) ;
4
+
5
+ amqp . connect ( 'amqp://localhost' ) . then ( function ( conn ) {
6
+ process . once ( 'SIGINT' , function ( ) { conn . close ( ) ; } ) ;
7
+ return conn . createChannel ( ) . then ( function ( ch ) {
8
+
9
+ var ok = ch . assertQueue ( 'hello' , { durable : false } ) ;
10
+
11
+ ok = ok . then ( function ( _qok ) {
12
+ return ch . consume ( 'hello' , function ( msg ) {
13
+ console . log ( " [x] Received '%s'" , msg . content . toString ( ) ) ;
14
+ } , { noAck : true } ) ;
15
+ } ) ;
16
+
17
+ return ok . then ( function ( _consumeOk ) {
18
+ console . log ( ' [*] Waiting for messages. To exit press CTRL+C' ) ;
19
+ } ) ;
20
+ } ) ;
21
+ } ) . then ( null , console . warn ) ;
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ var amqp = require ( 'amqplib' ) ;
4
+ var when = require ( 'when' ) ;
5
+
6
+ amqp . connect ( 'amqp://localhost' ) . then ( function ( conn ) {
7
+ return when ( conn . createChannel ( ) . then ( function ( ch ) {
8
+
9
+ var q = 'hello' ;
10
+ var ok = ch . assertQueue ( q , { durable : false } ) ;
11
+
12
+ return ok . then ( function ( _qok ) {
13
+ var msg = 'Hello World!' ;
14
+ ch . sendToQueue ( q , new Buffer ( msg ) ) ;
15
+ console . log ( " [x] Sent '%s'" , msg ) ;
16
+ return ch . close ( ) ;
17
+ } ) ;
18
+ } ) ) . ensure ( function ( ) { conn . close ( ) ; } ) ;
19
+ } ) . then ( null , console . warn ) ;
You can’t perform that action at this time.
0 commit comments