vulcain-corejs
Version:
Vulcain micro-service framework
38 lines (36 loc) • 1.36 kB
JavaScript
const guid = require('node-uuid');
const annotations_1 = require('../di/annotations');
const RX = require('rx');
class MessageBus {
constructor(manager) {
this.manager = manager;
this._events = new Map();
this.commandBus = manager.container.get(annotations_1.DefaultServiceNames.ActionBusAdapter);
this.commandBus.listenForTask(manager.domain.name, manager.serviceName, manager.consumeTaskAsync.bind(manager));
this.eventBus = manager.container.get(annotations_1.DefaultServiceNames.EventBusAdapter);
}
getEventsQueue(domain) {
let events = this._events.get(domain);
if (!events) {
events = new RX.Subject();
this._events.set(domain, events);
this.eventBus.listenForEvent(domain, this.consumeEventAsync.bind(this));
}
return events;
}
consumeEventAsync(event) {
this.getEventsQueue(event.domain).onNext(event);
}
pushTask(command) {
command.status = "Pending";
command.taskId = guid.v4();
this.commandBus.publishTask(command.domain, this.manager.serviceName, command);
}
sendEvent(response) {
delete response.inputSchema;
this.eventBus.sendEvent(response.domain, response);
}
}
exports.MessageBus = MessageBus;
//# sourceMappingURL=messageBus.js.map
;