File tree Expand file tree Collapse file tree 6 files changed +75
-0
lines changed
Expand file tree Collapse file tree 6 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ javascript-nodejs /node_modules
Original file line number Diff line number Diff line change 1+ # Node.js code for RabbitMQ tutorials
2+
3+ Here you can find Node.js code examples from [ RabbitMQ
4+ tutorials] ( http://www.rabbitmq.com/getstarted.html ) .
5+
6+ To successfully use the examples you will need a running RabbitMQ server.
7+
8+ ## Requirements
9+
10+ Apart from ` npm ` and ` node ` , to run this code you need
11+ [ ` node-amqp ` ] ( https://github.com/postwait/node-amqp ) version 0.1.X. To
12+ pull the dependency from ` npm ` run:
13+
14+ npm install
15+
16+ ## Code
17+
18+ [ Tutorial one: "Hello World!"] ( http://www.rabbitmq.com/tutorial-one-python.html ) :
19+
20+ node send.js
21+ node receive.js
22+
Original file line number Diff line number Diff line change 1+
2+ exports . safeEndConnection = function ( connection ) {
3+
4+ // `connection.end` doesn't flush outgoing buffers, run a
5+ // synchronous command to comprehend
6+
7+ connection . queue ( 'tmp-' + Math . random , { exclusive : true } , function ( ) {
8+ connection . end ( ) ;
9+
10+ // `connection.end` in 0.1.3 raises a ECONNRESET error, silence it:
11+ connection . once ( 'error' , function ( e ) {
12+ if ( e . code !== 'ECONNRESET' || e . syscall !== 'write' )
13+ throw e ;
14+ } ) ;
15+ } ) ;
16+
17+ } ;
18+
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " rabbitmq-tutorials" ,
3+ "version" : " 0.0.0-unreleasable" ,
4+ "private" : true ,
5+ "main" : " none" ,
6+ "description" : " Node.JS implementation of RabbitMQ tutorials" ,
7+ "dependencies" : {
8+ "amqp" : " 0.1.3"
9+ }
10+ }
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+ connection . on ( 'ready' , function ( ) {
7+ connection . queue ( 'hello' , { autoDelete : false } , function ( queue ) {
8+ queue . subscribe ( function ( msg ) {
9+ console . log ( " [x] Received %s" , msg . data . toString ( 'utf-8' ) ) ;
10+ } ) ;
11+ } ) ;
12+ console . log ( ' [*] Waiting for messages. To exit press CTRL+C' )
13+ } ) ;
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+ connection . on ( 'ready' , function ( ) {
7+ connection . publish ( 'hello' , 'Hello World!' ) ;
8+ console . log ( " [x] Sent 'Hello World!'" ) ;
9+
10+ amqp_hacks . safeEndConnection ( connection ) ;
11+ } ) ;
You can’t perform that action at this time.
0 commit comments