UNPKG

@message-queue-toolkit/sns

Version:
50 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractSnsSqsConsumer = void 0; const sqs_1 = require("@message-queue-toolkit/sqs"); const snsInitter_1 = require("../utils/snsInitter"); const snsMessageReader_1 = require("../utils/snsMessageReader"); class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer { subscriptionConfig; snsClient; stsClient; // @ts-ignore topicArn; // @ts-ignore subscriptionArn; constructor(dependencies, options, executionContext) { super(dependencies, { ...options, }, executionContext); this.subscriptionConfig = options.subscriptionConfig; this.snsClient = dependencies.snsClient; this.stsClient = dependencies.stsClient; } async init() { if (this.deletionConfig && this.creationConfig && this.subscriptionConfig) { await (0, snsInitter_1.deleteSnsSqs)(this.sqsClient, this.snsClient, this.stsClient, this.deletionConfig, this.creationConfig.queue, this.creationConfig.topic, this.subscriptionConfig, undefined, this.locatorConfig); } else if (this.deletionConfig && this.creationConfig) { await (0, sqs_1.deleteSqs)(this.sqsClient, this.deletionConfig, this.creationConfig); } const initSnsSqsResult = await (0, snsInitter_1.initSnsSqs)(this.sqsClient, this.snsClient, this.stsClient, this.locatorConfig, this.creationConfig, this.subscriptionConfig, { logger: this.logger }); this.queueName = initSnsSqsResult.queueName; this.queueUrl = initSnsSqsResult.queueUrl; this.topicArn = initSnsSqsResult.topicArn; this.subscriptionArn = initSnsSqsResult.subscriptionArn; await this.initDeadLetterQueue(); } resolveMessage(message) { const result = (0, snsMessageReader_1.readSnsMessage)(message, this.errorResolver); if (result.result) { return result; } // if it not an SNS message, then it is a SQS message return super.resolveMessage(message); } resolveSchema(messagePayload) { return this._messageSchemaContainer.resolveSchema(messagePayload); } } exports.AbstractSnsSqsConsumer = AbstractSnsSqsConsumer; //# sourceMappingURL=AbstractSnsSqsConsumer.js.map