event-message-broker
Version:
A Message Bus that uses AWS Stack and RabbitMQ
62 lines (61 loc) • 2.83 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AWSInfrastructure = void 0;
const o11y_1 = require("../../application/utils/o11y");
const SNSInfrastructure_1 = require("./SNSInfrastructure");
const SQSInfrastructure_1 = require("./SQSInfrastructure");
const api_1 = require("@opentelemetry/api");
class AWSInfrastructure {
constructor() {
this.sns = new SNSInfrastructure_1.SNSInfrastructure();
this.sqs = new SQSInfrastructure_1.SQSInfrastructure();
}
createQueue(queueName) {
return __awaiter(this, void 0, void 0, function* () {
const span = (0, o11y_1.startSpan)(this.createQueue.name, api_1.SpanKind.SERVER);
try {
yield this.sqs.create(queueName, span);
}
catch (error) {
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
span.recordException(error);
throw error;
}
finally {
span.end();
}
});
}
bindTopic(binder) {
return __awaiter(this, void 0, void 0, function* () {
const span = (0, o11y_1.startSpan)(this.createQueue.name, api_1.SpanKind.SERVER);
try {
const topicOutput = yield this.sns.create(binder.TopicName, span);
if (topicOutput.Created) {
const policy = yield this.sqs.linkTopicQueuePolicy(binder.QueueName, binder.TopicName);
span.addEvent('queue-policy-linked', { policy: JSON.stringify(policy) });
const arn = yield this.sns.subscribeEndpoints(binder.TopicName, binder.QueueName);
span.addEvent('endpoint-subscribed', { arn });
}
}
catch (error) {
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
span.recordException(error);
throw error;
}
finally {
span.end();
}
});
}
}
exports.AWSInfrastructure = AWSInfrastructure;