Skip to content

Instantly share code, notes, and snippets.

@DarcInc
Created March 19, 2014 13:25
Show Gist options
  • Save DarcInc/9641557 to your computer and use it in GitHub Desktop.
Save DarcInc/9641557 to your computer and use it in GitHub Desktop.
Node AMQ Message Producer
var queueName = 'tasks';
var exchangeName = 'taskExchange';
var key = 'all';
var amq = require('amq');
var readline = require('readline');
var connection = amq.createConnection(
{ host: 'localhost', debug: true },
{ reconnect: { strategy: 'constant', initial: 1000 } }
);
rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var queue = connection.queue(queueName, { durable: true });
var exchange = connection.exchange(exchangeName, { durable: true, type: 'topic', confirm: true });
queue.bind(exchange, key);
rl.setPrompt("> ");
rl.prompt();
rl.on('line', function(line) {
line = line.trim();
exchange.publish(key, line);
rl.prompt();
});
connection.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment