Skip to content

Instantly share code, notes, and snippets.

@omarkj
Created August 10, 2010 11:55
Show Gist options
  • Save omarkj/517141 to your computer and use it in GitHub Desktop.
Save omarkj/517141 to your computer and use it in GitHub Desktop.
Using EventEmitters
var amqp = require('./amqp'),
sys = require('sys'),
net = require('net'),
events = require('events');
var RabbitClient = function() {
events.EventEmitter.call(this);
var self = this;
var connection = amqp.createConnection({ host: cfg.AMQP.Host });
connection.addListener('ready', function () {
var q = connection.queue('market-queue', function() {
q.bind(cfg.AMQP.MarketQueue, cfg.AMQP.RoutingKey);
q.subscribe(function (message) {
var obj = JSON.parse(message);
self.emit('message', [obj]);
sys.debug('Recieved %s'.format(message.Symbol));
});
});
sys.puts('Now listening for %s/%s on server %s.'.format(cfg.AMQP.MarketQueue,
cfg.AMQP.RoutingKey, cfg.AMQP.Host));
});
};
sys.inherits(RabbitClient, events.EventEmitter);
var client = new RabbitClient();
exports.QueueClient = client;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment