UNPKG

vulcain-corejs

Version:
40 lines (38 loc) 1.44 kB
"use strict"; const guid = require('node-uuid'); const annotations_1 = require("../di/annotations"); const RX = require("rx"); class MessageBus { constructor(manager, hasAsyncActions) { this.manager = manager; this._events = new Map(); this.commandBus = manager.container.get(annotations_1.DefaultServiceNames.ActionBusAdapter); if (this.commandBus && hasAsyncActions) { this.commandBus.listenForTask(manager.domain.name, manager.serviceId, 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.serviceId, command); } sendEvent(response) { delete response.inputSchema; this.eventBus.sendEvent(response.domain, response); } } exports.MessageBus = MessageBus; //# sourceMappingURL=messageBus.js.map