File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ var amqp = require ( 'amqplib' ) ;
4+
5+ var conn = amqp . connect ( 'amqp://localhost' )
6+
7+ conn . then ( createChannel ) . then ( null , console . warn ) ;
8+
9+ function createChannel ( conn ) {
10+ process . once ( 'SIGINT' , function ( ) { conn . close ( ) ; } ) ;
11+ return conn . createChannel ( ) . then ( function ( ch ) {
12+ var ok = ch . assertExchange ( 'logs' , 'fanout' , { durable : false } ) ;
13+ ok = ok . then ( function ( ) {
14+ return ch . assertQueue ( '' , { exclusive : true } ) ;
15+ } ) ;
16+ ok = ok . then ( function ( qok ) {
17+ return ch . bindQueue ( qok . queue , 'logs' , '' ) . then ( function ( ) {
18+ return qok . queue ;
19+ } ) ;
20+ } ) ;
21+ ok = ok . then ( function ( queue ) {
22+ return ch . consume ( queue , logMessage , { noAck : true } ) ;
23+ } ) ;
24+ return ok . then ( function ( ) {
25+ console . log ( ' [*] Waiting for logs. To exit press CTRL+C' ) ;
26+ } ) ;
27+
28+ function logMessage ( msg ) {
29+ console . log ( " [x] '%s'" , msg . content . toString ( ) ) ;
30+ }
31+ } ) ;
32+ }
You can’t perform that action at this time.
0 commit comments