Created
November 29, 2013 18:25
-
-
Save yaronn/7709916 to your computer and use it in GitHub Desktop.
rabbitmq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#rabitmq is already installed in ubuntu | |
#start/stop/status | |
$> sudo rabbitmqctl status | |
OR | |
$> sudo invoke-rc.d rabbitmq-server status | |
#enable mgmt console | |
$> /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins enable rabbitmq_management | |
#mgmtconsole: | |
#http://localhost:55672/#/ | |
#guest | |
#guest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var amqp = require('amqp'); | |
var connection = amqp.createConnection(); | |
connection.on('ready', function() { | |
console.log('one'); | |
connection.exchange('sub18', { | |
autoDelete: false, | |
confirm: true, | |
durable: true, | |
type: 'direct' | |
}, function(exchange) { | |
console.log('exchange ready ' + exchange.name ); | |
for (var i=0; i<5; i++) { | |
var publish = exchange.publish('r1', { a: 'b'+i }, {immediate: false }, function(err) { | |
console.log('message published: ' + err); | |
}); | |
publish.addListener('ack', function(err) { | |
console.log('ack received: ' + err); | |
}); | |
console.log('message sent'); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var amqp = require('amqp'); | |
var connection = amqp.createConnection(); | |
connection.on('ready', function() { | |
connection.exchange("sub18", { | |
autoDelete: false, | |
confirm: true, | |
durable: true, | |
type: 'direct' | |
}, function(exchange) { | |
connection.queue('q18', { | |
autoDelete: false}, function(q) { | |
q.bind(exchange, 'r1'); | |
q.subscribe({ | |
ack: true, | |
prefetchCount: 2 | |
}, function(json, headers, deliveryInfo, m) { | |
console.log("msg: " + JSON.stringify(json)); | |
setTimeout(function() { | |
q.shift(); | |
}, 2000); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment