Skip to content
Browse files

node: Fixes to second

  • Loading branch information...
1 parent d3b0ab2 commit 0a546a5a00e401b0c852debc1ba7e0a53c3e7fcb @majek majek committed Apr 17, 2012
Showing with 26 additions and 2 deletions.
  1. +9 −1 javascript-nodejs/README.md
  2. +1 −1 javascript-nodejs/amqp-hacks.js
  3. +16 −0 javascript-nodejs/new_task.js
View
10 javascript-nodejs/README.md
@@ -11,7 +11,8 @@ Apart from `npm` and `node`, to run this code you need
[`node-amqp`](https://github.com/postwait/node-amqp) version 0.1.X. To
pull the dependency from `npm` run:
- npm install
+ npm install amqp
+
## Code
@@ -20,6 +21,13 @@ pull the dependency from `npm` run:
node send.js
node receive.js
+
+[Tutorial two: Work Queues](http://www.rabbitmq.com/tutorial-two-python.html):
+
+ node new_task.js "A very hard task which takes two seconds.."
+ node worker.js
+
+
[Tutorial three: Publish/Subscribe](http://www.rabbitmq.com/tutorial-three-python.html):
node receive_logs.js
View
2 javascript-nodejs/amqp-hacks.js
@@ -4,7 +4,7 @@ exports.safeEndConnection = function(connection) {
// `connection.end` doesn't flush outgoing buffers, run a
// synchronous command to comprehend
- connection.queue('tmp-' + Math.random, {exclusive: true}, function(){
+ connection.queue('tmp-' + Math.random(), {exclusive: true}, function(){
connection.end();
// `connection.end` in 0.1.3 raises a ECONNRESET error, silence it:
View
16 javascript-nodejs/new_task.js
@@ -0,0 +1,16 @@
+var amqp = require('amqp');
+var amqp_hacks = require('./amqp-hacks');
+
+var connection = amqp.createConnection({host: 'localhost'});
+
+var message = process.argv.slice(2).join(' ') || 'Hello World!';
+
+connection.on('ready', function(){
+ connection.queue('task_queue', {autoDelete: false,
+ durable: true}, function(queue){
+ connection.publish('task_queue', message, {deliveryMode: 2});
+ console.log(" [x] Sent %s", message);
+
+ amqp_hacks.safeEndConnection(connection);
+ });
+});

0 comments on commit 0a546a5

Please sign in to comment.
Something went wrong with that request. Please try again.