Skip to content

Instantly share code, notes, and snippets.

@boffbowsh
Created August 20, 2013 15:10
Show Gist options
  • Select an option

  • Save boffbowsh/6282700 to your computer and use it in GitHub Desktop.

Select an option

Save boffbowsh/6282700 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var amqp = require("amqp");
// Config
var fromHost = { host: 'message1', login: 'guest', password: 'guest' };
var toHost = { host: 'message3', login: 'guest', password: 'guest' };
var queueName = "queuename";
var queueOpts = {durable: true, passive: true, noDeclare: true};
var exchangeName = "exchangename";
var exchangeOpts = { type: 'direct', durable: true, passive: true, noDeclare: true };
// Enc Config
var fromConnection = amqp.createConnection(fromHost);
fromConnection.on("ready", function() {
console.log('connected to from');
var toConnection = amqp.createConnection(toHost);
toConnection.on("ready", function() {
console.log('connected to to');
toConnection.exchange(exchangeName, exchangeOpts, function(exch) {
fromConnection.queue(queueName, queueOpts, function(q){
q.subscribe({ack: true, prefetchCount: 10}, function(message, headers, deliveryInfo) {
console.log(arguments)
console.log("Pushing message at " + deliveryInfo.timestamp);
exch.publish(deliveryInfo.routingKey, "{}", deliveryInfo);
q.shift();
});
});
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment