Created
August 10, 2010 11:55
-
-
Save omarkj/517141 to your computer and use it in GitHub Desktop.
Using EventEmitters
This file contains 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'), | |
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