airship-server
Version:
Airship is a framework for Node.JS & TypeScript that helps you to write big, scalable and maintainable API servers.
37 lines • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const BaseBroadcastTransmitter_1 = require("../domain/BaseBroadcastTransmitter");
const amqp = require('amqplib/callback_api');
const env = process.env['NODE_ENV'] || 'development';
const QUEUE = {
'production': 'hh_events_notifications',
'test': 'hh_events_notifications_testing',
'development': 'hh_events_notifications'
};
class RabbitBroadcastTransmitter extends BaseBroadcastTransmitter_1.BaseBroadcastTransmitter {
constructor(rabbitLink) {
super();
//private _queue = 'hh_events_notifications'
this._queue = QUEUE[env];
this._waitingQueue = [];
this._rabbitLink = rabbitLink;
this._connection = amqp.connect(rabbitLink, (err, conn) => {
conn.createChannel((err, ch) => {
this._channel = ch;
ch.assertQueue(this._queue, { durable: false });
if (this._waitingQueue.length > 0) {
this._waitingQueue.forEach(m => this.transmit(m));
}
});
});
}
transmit(subscription) {
if (this._channel != undefined) {
this._channel.sendToQueue(this._queue, new Buffer(JSON.stringify(subscription.serialize())), { persistent: true });
}
else
this._waitingQueue.push(subscription);
}
}
exports.default = RabbitBroadcastTransmitter;
//# sourceMappingURL=RabbitBroadcastTransmitter.js.map