UNPKG

@message-queue-toolkit/sns

Version:
46 lines 2.1 kB
import { AbstractSqsConsumer, deleteSqs } from '@message-queue-toolkit/sqs'; import { deleteSnsSqs, initSnsSqs } from "../utils/snsInitter.js"; import { readSnsMessage } from "../utils/snsMessageReader.js"; export class AbstractSnsSqsConsumer extends 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 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 deleteSqs(this.sqsClient, this.deletionConfig, this.creationConfig); } const initSnsSqsResult = await 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 = 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); } } //# sourceMappingURL=AbstractSnsSqsConsumer.js.map