File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -20,3 +20,7 @@ pull the dependency from `npm` run:
2020 node send.js
2121 node receive.js
2222
23+ [ Tutorial three: Publish/Subscribe] ( http://www.rabbitmq.com/tutorial-three-python.html ) :
24+
25+ node receive_logs.js
26+ node emit_log.js "info: This is the log message"
Original file line number Diff line number Diff line change 1+ var amqp = require ( 'amqp' ) ;
2+ var amqp_hacks = require ( './amqp-hacks' ) ;
3+
4+ var connection = amqp . createConnection ( { host : 'localhost' } ) ;
5+
6+ var message = process . argv . slice ( 2 ) . join ( ' ' ) || 'Hello World!' ;
7+
8+ connection . on ( 'ready' , function ( ) {
9+ connection . exchange ( 'logs' , { type : 'fanout' ,
10+ autoDelete : false } , function ( exchange ) {
11+ exchange . publish ( '' , message ) ;
12+ console . log ( " [x] Sent %s" , message ) ;
13+
14+ amqp_hacks . safeEndConnection ( connection ) ;
15+ } ) ;
16+ } ) ;
Original file line number Diff line number Diff line change 1+ var amqp = require ( 'amqp' ) ;
2+
3+ var connection = amqp . createConnection ( { host : 'localhost' } ) ;
4+
5+ connection . on ( 'ready' , function ( ) {
6+ connection . exchange ( 'logs' , { type : 'fanout' ,
7+ autoDelete : false } , function ( exchange ) {
8+ connection . queue ( 'tmp-' + Math . random ( ) , { exclusive : true } ,
9+ function ( queue ) {
10+ queue . bind ( 'logs' , '' ) ;
11+ console . log ( ' [*] Waiting for logs. To exit press CTRL+C' )
12+
13+ queue . subscribe ( function ( msg ) {
14+ console . log ( " [x] %s" , msg . data . toString ( 'utf-8' ) ) ;
15+ } ) ;
16+ } )
17+ } ) ;
18+ } ) ;
You can’t perform that action at this time.
0 commit comments