@nestjstools/messaging-amazon-sqs-extension
Version:
Extension to handle messages and dispatch them over Amazon SQS
49 lines • 2.52 kB
JavaScript
;
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AmazonSqsMessageBus = void 0;
const common_1 = require("@nestjs/common");
const amazon_sqs_channel_1 = require("../channel/amazon-sqs.channel");
const client_sqs_1 = require("@aws-sdk/client-sqs");
const amazon_sqs_message_options_1 = require("../message/amazon-sqs-message-options");
let AmazonSqsMessageBus = class AmazonSqsMessageBus {
channel;
constructor(channel) {
this.channel = channel;
}
async dispatch(message) {
const messageOptions = message.messageOptions;
let attributes = {};
if (messageOptions !== undefined &&
!(messageOptions instanceof amazon_sqs_message_options_1.AmazonSqsMessageOptions)) {
throw new Error(`Message options must be a ${amazon_sqs_message_options_1.AmazonSqsMessageOptions.name} object`);
}
if (messageOptions instanceof amazon_sqs_message_options_1.AmazonSqsMessageOptions) {
attributes = messageOptions.attributes;
}
attributes.messagingRoutingKey = {
DataType: 'String',
StringValue: message.messageRoutingKey,
};
const command = new client_sqs_1.SendMessageCommand({
QueueUrl: this.channel.config.queueUrl,
MessageBody: JSON.stringify(message.message),
MessageAttributes: attributes,
});
await this.channel.client.send(command);
}
};
exports.AmazonSqsMessageBus = AmazonSqsMessageBus;
exports.AmazonSqsMessageBus = AmazonSqsMessageBus = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [amazon_sqs_channel_1.AmazonSqsChannel])
], AmazonSqsMessageBus);
//# sourceMappingURL=amazon-sqs-message.bus.js.map