node: Fixes to second
This commit is contained in:
parent
d3b0ab2ebe
commit
0a546a5a00
@ -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
|
||||
|
@ -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:
|
||||
|
16
javascript-nodejs/new_task.js
Normal file
16
javascript-nodejs/new_task.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user