event-message-broker
Version:
A Message Bus that uses AWS Stack and RabbitMQ
56 lines (55 loc) • 2.54 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { AWSBus } from './aws-provider/services/AWSBus';
import { Configuration } from './application/utils/configurations';
import { AWSInfrastructure } from './aws-provider/infrastructure/AWSInfrastructure';
import { RabbitMqInfrastructure } from './rabbitmq-provider/infrastructure/RabbitMqInfrastructure';
import { RabbitMQBus } from './rabbitmq-provider/services/RabbitMQBus';
import { RabbitMqContext } from './rabbitmq-provider/infrastructure/RabbitMqContext';
export class MessageBus {
static useAws() {
this.infrastructure = new AWSInfrastructure();
this.bus = new AWSBus();
return this;
}
static useRabbitMq() {
return __awaiter(this, void 0, void 0, function* () {
const channel = yield RabbitMqContext.configureContext();
this.infrastructure = new RabbitMqInfrastructure(channel);
this.bus = new RabbitMQBus(channel);
return this;
});
}
static configureTags(tags) {
Configuration.pushTags(tags);
return this;
}
static configurePrefetch(prefetch) {
Configuration.configurePrefetch(prefetch);
return this;
}
static get Bus() {
return this.bus;
}
static configureEndpoints(endpoints) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.infrastructure || !this.bus) {
throw new Error('Need to define what provider will be use');
}
yield Promise.all(endpoints.map((endpoint) => __awaiter(this, void 0, void 0, function* () {
yield this.infrastructure.createQueue(endpoint.Queue);
yield this.infrastructure.bindTopic({
QueueName: endpoint.Queue,
TopicName: endpoint.Topic
});
})));
});
}
}