UNPKG

@mbc-cqrs-serverless/core

Version:
89 lines 3.67 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var SqsService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.SqsService = void 0; const client_sqs_1 = require("@aws-sdk/client-sqs"); const common_1 = require("@nestjs/common"); const sqs_client_factory_1 = require("./sqs-client-factory"); let SqsService = SqsService_1 = class SqsService { constructor(sqsClientFactory) { this.sqsClientFactory = sqsClientFactory; this.logger = new common_1.Logger(SqsService_1.name); } /** * Send a single message to an SQS queue. */ async sendMessage(queueUrl, body, opts) { const client = this.sqsClientFactory.getClient(); const result = await client.send(new client_sqs_1.SendMessageCommand({ ...opts, QueueUrl: queueUrl, MessageBody: body, })); this.logger.debug(`sendMessage MessageId=${result.MessageId}`); return result; } /** * Send up to 10 messages to an SQS queue in a single API call. * Caller is responsible for ensuring entries.length <= 10. */ async sendMessageBatch(queueUrl, entries) { const client = this.sqsClientFactory.getClient(); const result = await client.send(new client_sqs_1.SendMessageBatchCommand({ QueueUrl: queueUrl, Entries: entries, })); return result; } /** * Receive messages from an SQS queue. */ async receiveMessages(queueUrl, opts) { const client = this.sqsClientFactory.getClient(); const result = await client.send(new client_sqs_1.ReceiveMessageCommand({ MaxNumberOfMessages: 10, WaitTimeSeconds: 0, ...opts, QueueUrl: queueUrl, })); return result; } /** * Delete a single message from an SQS queue (acknowledge processing). */ async deleteMessage(queueUrl, receiptHandle) { const client = this.sqsClientFactory.getClient(); const result = await client.send(new client_sqs_1.DeleteMessageCommand({ QueueUrl: queueUrl, ReceiptHandle: receiptHandle, })); this.logger.debug(`deleteMessage receiptHandle=${receiptHandle.slice(0, 20)}...`); return result; } /** * Delete up to 10 messages from an SQS queue in a single API call. */ async deleteMessageBatch(queueUrl, entries) { const client = this.sqsClientFactory.getClient(); const result = await client.send(new client_sqs_1.DeleteMessageBatchCommand({ QueueUrl: queueUrl, Entries: entries, })); return result; } }; exports.SqsService = SqsService; exports.SqsService = SqsService = SqsService_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [sqs_client_factory_1.SqsClientFactory]) ], SqsService); //# sourceMappingURL=sqs.service.js.map