@nestjstools/messaging-amazon-sqs-extension 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -0
- package/lib/channel/amazon-sqs.channel-config.d.ts +19 -0
- package/lib/channel/amazon-sqs.channel-config.js +36 -0
- package/lib/channel/amazon-sqs.channel-config.js.map +1 -0
- package/lib/channel/amazon-sqs.channel-factory.d.ts +6 -0
- package/lib/channel/amazon-sqs.channel-factory.js +24 -0
- package/lib/channel/amazon-sqs.channel-factory.js.map +1 -0
- package/lib/channel/amazon-sqs.channel.d.ts +7 -0
- package/lib/channel/amazon-sqs.channel.js +24 -0
- package/lib/channel/amazon-sqs.channel.js.map +1 -0
- package/lib/consumer/amazon-sqs-messaging.consumer.d.ts +11 -0
- package/lib/consumer/amazon-sqs-messaging.consumer.js +64 -0
- package/lib/consumer/amazon-sqs-messaging.consumer.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -0
- package/lib/message-bus/amazon-sqs-message-bus-factory.d.ts +6 -0
- package/lib/message-bus/amazon-sqs-message-bus-factory.js +24 -0
- package/lib/message-bus/amazon-sqs-message-bus-factory.js.map +1 -0
- package/lib/message-bus/amazon-sqs-message.bus.d.ts +8 -0
- package/lib/message-bus/amazon-sqs-message.bus.js +40 -0
- package/lib/message-bus/amazon-sqs-message.bus.js.map +1 -0
- package/lib/messaging-amazon-sqs-extension.module.d.ts +2 -0
- package/lib/messaging-amazon-sqs-extension.module.js +27 -0
- package/lib/messaging-amazon-sqs-extension.module.js.map +1 -0
- package/lib/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +109 -0
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<image src="nestjstools-logo.png" width="400">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @nestjstools/messaging-amazon-sqs -extension
|
|
6
|
+
|
|
7
|
+
A NestJS library for managing asynchronous and synchronous messages with support for buses, handlers, channels, and consumers. This library simplifies building scalable and decoupled applications by facilitating robust message handling pipelines while ensuring flexibility and reliability.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extension
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extension
|
|
19
|
+
```
|
|
20
|
+
## AmazonSQS Integration: Messaging Configuration Example
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Module } from '@nestjs/common';
|
|
26
|
+
import { MessagingModule } from '@nestjstools/messaging';
|
|
27
|
+
import { SendMessageHandler } from './handlers/send-message.handler';
|
|
28
|
+
import { MessagerAmazonSQSExtensionModule, AmazonSQSChannelConfig } from "@nestjstools/messager-amazon-sqs-extension";
|
|
29
|
+
|
|
30
|
+
@Module({
|
|
31
|
+
imports: [
|
|
32
|
+
MessagerAmazonSQSExtensionModule, // Importing the SQS extension module
|
|
33
|
+
MessagingModule.forRoot({
|
|
34
|
+
buses: [
|
|
35
|
+
{
|
|
36
|
+
name: 'sqs-event.bus',
|
|
37
|
+
channels: ['sqs-event'],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
channels: [
|
|
41
|
+
new AmazonSqsChannelConfig({
|
|
42
|
+
name: 'sqs-event',
|
|
43
|
+
enableConsumer: true, // Enable if you want to consume messages
|
|
44
|
+
region: 'us-east-1',
|
|
45
|
+
queueUrl: 'http://localhost:9324/queue/test_queue', // ElasticMQ for local development
|
|
46
|
+
autoCreate: true, // Auto-create queue if it doesn't exist
|
|
47
|
+
credentials: { // Optional credentials for SQS
|
|
48
|
+
accessKeyId: 'x',
|
|
49
|
+
secretAccessKey: 'x',
|
|
50
|
+
},
|
|
51
|
+
maxNumberOfMessages: 3, // optional
|
|
52
|
+
visibilityTimeout: 10, // optional
|
|
53
|
+
waitTimeSeconds: 5, // Every 5 seconds consumer will pull 3 messages from queue - optional
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
debug: true, // Optional: Enable debugging for Messaging operations
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
export class AppModule {}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Dispatch messages via bus (example)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { Controller, Get } from '@nestjs/common';
|
|
67
|
+
import { CreateUser } from './application/command/create-user';
|
|
68
|
+
import { IMessageBus, MessageBus, RoutingMessage } from '@nestjstools/messaging';
|
|
69
|
+
|
|
70
|
+
@Controller()
|
|
71
|
+
export class AppController {
|
|
72
|
+
constructor(
|
|
73
|
+
@MessageBus('sqs-event.bus') private sqsMessageBus: IMessageBus,
|
|
74
|
+
) {}
|
|
75
|
+
|
|
76
|
+
@Get('/sqs')
|
|
77
|
+
createUserAsyncViaPuSubBus(): string {
|
|
78
|
+
this.sqsMessageBus.dispatch(new RoutingMessage(new CreateUser('John FROM SQS'), 'my_app_command.create_user'));
|
|
79
|
+
|
|
80
|
+
return 'Message sent';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Handler for your message
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { CreateUser } from '../create-user';
|
|
89
|
+
import { IMessageBus, IMessageHandler, MessageBus, MessageHandler, RoutingMessage, DenormalizeMessage } from '@nestjstools/messaging';
|
|
90
|
+
|
|
91
|
+
@MessageHandler('my_app_command.create_user')
|
|
92
|
+
export class CreateUserHandler implements IMessageHandler<CreateUser>{
|
|
93
|
+
|
|
94
|
+
handle(message: CreateUser): Promise<void> {
|
|
95
|
+
console.log(message);
|
|
96
|
+
// TODO Logic there
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### Key Features:
|
|
104
|
+
|
|
105
|
+
* Amazon SQS Integration: Easily send and receive messages with Amazon SQS.
|
|
106
|
+
|
|
107
|
+
* Local Development Support: Works with ElasticMQ for local development and testing.
|
|
108
|
+
|
|
109
|
+
* Automatic Queue Creation: Automatically create queues if they don’t exist (when autoCreate: true).
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Configuration options
|
|
114
|
+
|
|
115
|
+
### AmazonSqsChannel
|
|
116
|
+
|
|
117
|
+
#### **AmazonSqsChannelConfig**
|
|
118
|
+
| **Property** | **Description** | **Default Value** |
|
|
119
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------ |-------------------|
|
|
120
|
+
| **`name`** | The name of the Amazon SQS channel (e.g., `'sqs-event'`). | |
|
|
121
|
+
| **`region`** | The AWS region for the SQS queue (e.g., `'us-east-1'`). | |
|
|
122
|
+
| **`queueUrl`** | The URL of the SQS queue (e.g., `'http://localhost:9324/queue/test_queue'`). | |
|
|
123
|
+
| **`credentials`** | AWS credentials for SQS (optional). | |
|
|
124
|
+
| **`enableConsumer`** | Whether to enable message consumption (i.e., processing received messages). | `true` |
|
|
125
|
+
| **`autoCreate`** | Automatically create the queue if it doesn’t exist. | `true` |
|
|
126
|
+
| **`maxNumberOfMessages`** | The maximum number of messages to retrieve from the queue in one request. | 1 |
|
|
127
|
+
| **`visibilityTimeout`** | The time in seconds that the message will remain invisible to other consumers after being fetched. | 20 |
|
|
128
|
+
| **`waitTimeSeconds`** | The amount of time (in seconds) for long polling. The consumer will wait up to this time for messages. | 10 |
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Real world working example with RabbitMQ & Redis - but might be helpful to understand how it works
|
|
132
|
+
https://github.com/nestjstools/messaging-rabbitmq-example
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChannelConfig } from '@nestjstools/messaging';
|
|
2
|
+
export declare class AmazonSqsChannelConfig extends ChannelConfig {
|
|
3
|
+
readonly credentials?: Credentials;
|
|
4
|
+
readonly queueUrl: string;
|
|
5
|
+
readonly queueName?: string;
|
|
6
|
+
readonly endpoint?: string;
|
|
7
|
+
readonly region: string;
|
|
8
|
+
readonly maxNumberOfMessages?: number;
|
|
9
|
+
readonly visibilityTimeout?: number;
|
|
10
|
+
readonly waitTimeSeconds?: number;
|
|
11
|
+
readonly autoCreate?: boolean;
|
|
12
|
+
constructor({ name, credentials, queueUrl, maxNumberOfMessages, visibilityTimeout, waitTimeSeconds, region, autoCreate, enableConsumer, avoidErrorsForNotExistedHandlers, middlewares, normalizer, }: AmazonSqsChannelConfig);
|
|
13
|
+
}
|
|
14
|
+
interface Credentials {
|
|
15
|
+
accessKeyId: string;
|
|
16
|
+
secretAccessKey: string;
|
|
17
|
+
sessionToken?: string;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmazonSqsChannelConfig = void 0;
|
|
4
|
+
const messaging_1 = require("@nestjstools/messaging");
|
|
5
|
+
class AmazonSqsChannelConfig extends messaging_1.ChannelConfig {
|
|
6
|
+
credentials;
|
|
7
|
+
queueUrl;
|
|
8
|
+
queueName;
|
|
9
|
+
endpoint;
|
|
10
|
+
region;
|
|
11
|
+
maxNumberOfMessages;
|
|
12
|
+
visibilityTimeout;
|
|
13
|
+
waitTimeSeconds;
|
|
14
|
+
autoCreate;
|
|
15
|
+
constructor({ name, credentials, queueUrl, maxNumberOfMessages, visibilityTimeout, waitTimeSeconds, region, autoCreate, enableConsumer, avoidErrorsForNotExistedHandlers, middlewares, normalizer, }) {
|
|
16
|
+
super(name, avoidErrorsForNotExistedHandlers, middlewares, enableConsumer, normalizer);
|
|
17
|
+
let url;
|
|
18
|
+
try {
|
|
19
|
+
url = new URL(queueUrl);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
throw new Error(`Invalid queue url (${queueUrl})`);
|
|
23
|
+
}
|
|
24
|
+
this.credentials = credentials;
|
|
25
|
+
this.queueUrl = queueUrl;
|
|
26
|
+
this.queueName = url.pathname.split('/').pop();
|
|
27
|
+
this.endpoint = `${url.protocol}//${url.host}`;
|
|
28
|
+
this.region = region;
|
|
29
|
+
this.maxNumberOfMessages = maxNumberOfMessages ?? 1;
|
|
30
|
+
this.visibilityTimeout = visibilityTimeout ?? 20;
|
|
31
|
+
this.waitTimeSeconds = waitTimeSeconds ?? 10;
|
|
32
|
+
this.autoCreate = autoCreate ?? false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.AmazonSqsChannelConfig = AmazonSqsChannelConfig;
|
|
36
|
+
//# sourceMappingURL=amazon-sqs.channel-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-sqs.channel-config.js","sourceRoot":"","sources":["../../src/channel/amazon-sqs.channel-config.ts"],"names":[],"mappings":";;;AAAA,sDAAuD;AAEvD,MAAa,sBAAuB,SAAQ,yBAAa;IACvC,WAAW,CAAe;IAC1B,QAAQ,CAAS;IACjB,SAAS,CAAU;IACnB,QAAQ,CAAU;IAClB,MAAM,CAAS;IACf,mBAAmB,CAAU;IAC7B,iBAAiB,CAAU;IAC3B,eAAe,CAAU;IACzB,UAAU,CAAW;IAErC,YAAY,EACE,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,MAAM,EACN,UAAU,EACV,cAAc,EACd,gCAAgC,EAChC,WAAW,EACX,UAAU,GACa;QACnC,KAAK,CAAC,IAAI,EAAE,gCAAgC,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QACvF,IAAI,GAAG,CAAC;QACR,IAAI,CAAC;YACH,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,GAAG,CAAC,CAAA;QACpD,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,KAAK,CAAC;IACxC,CAAC;CACF;AA3CD,wDA2CC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AmazonSqsChannel } from './amazon-sqs.channel';
|
|
2
|
+
import { IChannelFactory } from '@nestjstools/messaging';
|
|
3
|
+
import { AmazonSqsChannelConfig } from './amazon-sqs.channel-config';
|
|
4
|
+
export declare class AmazonSqsChannelFactory implements IChannelFactory<AmazonSqsChannelConfig> {
|
|
5
|
+
create(channelConfig: AmazonSqsChannelConfig): AmazonSqsChannel;
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AmazonSqsChannelFactory = void 0;
|
|
10
|
+
const amazon_sqs_channel_1 = require("./amazon-sqs.channel");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const messaging_1 = require("@nestjstools/messaging");
|
|
13
|
+
const amazon_sqs_channel_config_1 = require("./amazon-sqs.channel-config");
|
|
14
|
+
let AmazonSqsChannelFactory = class AmazonSqsChannelFactory {
|
|
15
|
+
create(channelConfig) {
|
|
16
|
+
return new amazon_sqs_channel_1.AmazonSqsChannel(channelConfig);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.AmazonSqsChannelFactory = AmazonSqsChannelFactory;
|
|
20
|
+
exports.AmazonSqsChannelFactory = AmazonSqsChannelFactory = __decorate([
|
|
21
|
+
(0, common_1.Injectable)(),
|
|
22
|
+
(0, messaging_1.ChannelFactory)(amazon_sqs_channel_config_1.AmazonSqsChannelConfig)
|
|
23
|
+
], AmazonSqsChannelFactory);
|
|
24
|
+
//# sourceMappingURL=amazon-sqs.channel-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-sqs.channel-factory.js","sourceRoot":"","sources":["../../src/channel/amazon-sqs.channel-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6DAAwD;AACxD,2CAA0C;AAC1C,sDAAyE;AACzE,2EAAqE;AAI9D,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAClC,MAAM,CAAC,aAAqC;QAC1C,OAAO,IAAI,qCAAgB,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAJY,0DAAuB;kCAAvB,uBAAuB;IAFnC,IAAA,mBAAU,GAAE;IACZ,IAAA,0BAAc,EAAC,kDAAsB,CAAC;GAC1B,uBAAuB,CAInC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Channel } from '@nestjstools/messaging';
|
|
2
|
+
import { AmazonSqsChannelConfig } from './amazon-sqs.channel-config';
|
|
3
|
+
import { SQSClient } from '@aws-sdk/client-sqs';
|
|
4
|
+
export declare class AmazonSqsChannel extends Channel<AmazonSqsChannelConfig> {
|
|
5
|
+
readonly client: SQSClient;
|
|
6
|
+
constructor(config: AmazonSqsChannelConfig);
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmazonSqsChannel = void 0;
|
|
4
|
+
const messaging_1 = require("@nestjstools/messaging");
|
|
5
|
+
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
6
|
+
class AmazonSqsChannel extends messaging_1.Channel {
|
|
7
|
+
client;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
super(config);
|
|
10
|
+
this.client = new client_sqs_1.SQSClient({
|
|
11
|
+
endpoint: config.endpoint,
|
|
12
|
+
region: config.region,
|
|
13
|
+
credentials: config.credentials,
|
|
14
|
+
});
|
|
15
|
+
if (!config.autoCreate) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
this.client.send(new client_sqs_1.CreateQueueCommand({
|
|
19
|
+
QueueName: config.queueName,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AmazonSqsChannel = AmazonSqsChannel;
|
|
24
|
+
//# sourceMappingURL=amazon-sqs.channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-sqs.channel.js","sourceRoot":"","sources":["../../src/channel/amazon-sqs.channel.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AAEjD,oDAAoE;AAGpE,MAAa,gBAAiB,SAAQ,mBAA+B;IACnD,MAAM,CAAY;IAElC,YAAY,MAA8B;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAS,CAAC;YAC1B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,+BAAkB,CAAC;YACtC,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAnBD,4CAmBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AmazonSqsChannel } from '../channel/amazon-sqs.channel';
|
|
2
|
+
import { IMessagingConsumer } from '@nestjstools/messaging';
|
|
3
|
+
import { ConsumerMessageDispatcher } from '@nestjstools/messaging';
|
|
4
|
+
import { OnApplicationShutdown } from '@nestjs/common';
|
|
5
|
+
import { ConsumerDispatchedMessageError } from '@nestjstools/messaging';
|
|
6
|
+
export declare class AmazonSqsMessagingConsumer implements IMessagingConsumer<AmazonSqsChannel>, OnApplicationShutdown {
|
|
7
|
+
private channel?;
|
|
8
|
+
consume(dispatcher: ConsumerMessageDispatcher, channel: AmazonSqsChannel): Promise<void>;
|
|
9
|
+
onError(errored: ConsumerDispatchedMessageError, channel: AmazonSqsChannel): Promise<void>;
|
|
10
|
+
onApplicationShutdown(signal?: string): Promise<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AmazonSqsMessagingConsumer = void 0;
|
|
10
|
+
const amazon_sqs_channel_1 = require("../channel/amazon-sqs.channel");
|
|
11
|
+
const messaging_1 = require("@nestjstools/messaging");
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const messaging_2 = require("@nestjstools/messaging");
|
|
14
|
+
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
15
|
+
let AmazonSqsMessagingConsumer = class AmazonSqsMessagingConsumer {
|
|
16
|
+
channel = undefined;
|
|
17
|
+
async consume(dispatcher, channel) {
|
|
18
|
+
this.channel = channel;
|
|
19
|
+
const client = this.channel.client;
|
|
20
|
+
async function processPollMessages() {
|
|
21
|
+
const delay = (s) => new Promise(resolve => setTimeout(resolve, s * 1000));
|
|
22
|
+
while (true) {
|
|
23
|
+
const receiveParams = {
|
|
24
|
+
QueueUrl: channel.config.queueUrl,
|
|
25
|
+
MaxNumberOfMessages: channel.config.maxNumberOfMessages,
|
|
26
|
+
WaitTimeSeconds: channel.config.waitTimeSeconds,
|
|
27
|
+
VisibilityTimeout: channel.config.visibilityTimeout,
|
|
28
|
+
MessageAttributeNames: ["All"],
|
|
29
|
+
};
|
|
30
|
+
const response = await client.send(new client_sqs_1.ReceiveMessageCommand(receiveParams));
|
|
31
|
+
if (response.Messages && response.Messages.length > 0) {
|
|
32
|
+
for (const message of response.Messages) {
|
|
33
|
+
const attrs = message.MessageAttributes;
|
|
34
|
+
const messageBody = message.Body;
|
|
35
|
+
const routingKey = attrs.messagingRoutingKey.StringValue;
|
|
36
|
+
dispatcher.dispatch(new messaging_1.ConsumerMessage(JSON.parse(messageBody), routingKey));
|
|
37
|
+
const deleteParams = {
|
|
38
|
+
QueueUrl: channel.config.queueUrl,
|
|
39
|
+
ReceiptHandle: message.ReceiptHandle,
|
|
40
|
+
};
|
|
41
|
+
await client.send(new client_sqs_1.DeleteMessageCommand(deleteParams));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
await delay(channel.config.waitTimeSeconds);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
processPollMessages();
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
|
50
|
+
async onError(errored, channel) {
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
async onApplicationShutdown(signal) {
|
|
54
|
+
if (this.channel) {
|
|
55
|
+
this.channel.client.destroy();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.AmazonSqsMessagingConsumer = AmazonSqsMessagingConsumer;
|
|
60
|
+
exports.AmazonSqsMessagingConsumer = AmazonSqsMessagingConsumer = __decorate([
|
|
61
|
+
(0, common_1.Injectable)(),
|
|
62
|
+
(0, messaging_2.MessageConsumer)(amazon_sqs_channel_1.AmazonSqsChannel)
|
|
63
|
+
], AmazonSqsMessagingConsumer);
|
|
64
|
+
//# sourceMappingURL=amazon-sqs-messaging.consumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-sqs-messaging.consumer.js","sourceRoot":"","sources":["../../src/consumer/amazon-sqs-messaging.consumer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sEAAiE;AACjE,sDAA6E;AAE7E,2CAAmE;AACnE,sDAAyD;AAEzD,oDAI6B;AAItB,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAC7B,OAAO,GAAsB,SAAS,CAAC;IAE/C,KAAK,CAAC,OAAO,CAAC,UAAqC,EAAE,OAAyB;QAC5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAEnC,KAAK,UAAU,mBAAmB;YAChC,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACnF,OAAO,IAAI,EAAE,CAAC;gBACV,MAAM,aAAa,GAAG;oBACpB,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ;oBACjC,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB;oBACvD,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe;oBAC/C,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB;oBACnD,qBAAqB,EAAE,CAAC,KAAK,CAAC;iBAC/B,CAAC;gBAEF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,kCAAqB,CAAC,aAAa,CAAC,CAAC,CAAC;gBAE7E,IAAI,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtD,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;wBACxC,MAAM,KAAK,GAAG,OAAO,CAAC,iBAA0D,CAAC;wBACjF,MAAM,WAAW,GAAG,OAAO,CAAC,IAAc,CAAC;wBAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,mBAAmB,CAAC,WAAqB,CAAC;wBACnE,UAAU,CAAC,QAAQ,CAAC,IAAI,2BAAe,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,CAAC,CAAA;wBAC7E,MAAM,YAAY,GAAG;4BACnB,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ;4BACjC,aAAa,EAAE,OAAO,CAAC,aAAa;yBACrC,CAAC;wBACF,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,iCAAoB,CAAC,YAAY,CAAC,CAAC,CAAC;oBAC5D,CAAC;gBACH,CAAC;gBACH,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,eAAyB,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;QAED,mBAAmB,EAAE,CAAC;QAEtB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAuC,EAAE,OAAyB;QAC9E,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,MAAe;QACzC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;CACF,CAAA;AAnDY,gEAA0B;qCAA1B,0BAA0B;IAFtC,IAAA,mBAAU,GAAE;IACZ,IAAA,2BAAe,EAAC,qCAAgB,CAAC;GACrB,0BAA0B,CAmDtC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./messaging-amazon-sqs-extension.module"), exports);
|
|
18
|
+
__exportStar(require("./channel/amazon-sqs.channel-config"), exports);
|
|
19
|
+
__exportStar(require("./message-bus/amazon-sqs-message.bus"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAAuD;AACvD,sEAAmD;AACnD,uEAAoD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IMessageBusFactory } from "@nestjstools/messaging";
|
|
2
|
+
import { IMessageBus } from "@nestjstools/messaging";
|
|
3
|
+
import { AmazonSqsChannel } from '../channel/amazon-sqs.channel';
|
|
4
|
+
export declare class AmazonSqsMessageBusFactory implements IMessageBusFactory<AmazonSqsChannel> {
|
|
5
|
+
create(channel: AmazonSqsChannel): IMessageBus;
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AmazonSqsMessageBusFactory = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const amazon_sqs_message_bus_1 = require("./amazon-sqs-message.bus");
|
|
12
|
+
const messaging_1 = require("@nestjstools/messaging");
|
|
13
|
+
const amazon_sqs_channel_1 = require("../channel/amazon-sqs.channel");
|
|
14
|
+
let AmazonSqsMessageBusFactory = class AmazonSqsMessageBusFactory {
|
|
15
|
+
create(channel) {
|
|
16
|
+
return new amazon_sqs_message_bus_1.AmazonSqsMessageBus(channel);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.AmazonSqsMessageBusFactory = AmazonSqsMessageBusFactory;
|
|
20
|
+
exports.AmazonSqsMessageBusFactory = AmazonSqsMessageBusFactory = __decorate([
|
|
21
|
+
(0, common_1.Injectable)(),
|
|
22
|
+
(0, messaging_1.MessageBusFactory)(amazon_sqs_channel_1.AmazonSqsChannel)
|
|
23
|
+
], AmazonSqsMessageBusFactory);
|
|
24
|
+
//# sourceMappingURL=amazon-sqs-message-bus-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-sqs-message-bus-factory.js","sourceRoot":"","sources":["../../src/message-bus/amazon-sqs-message-bus-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,qEAA+D;AAE/D,sDAAyD;AAEzD,sEAAiE;AAI1D,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAErC,MAAM,CAAC,OAAyB;QAC9B,OAAO,IAAI,4CAAmB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AALY,gEAA0B;qCAA1B,0BAA0B;IAFtC,IAAA,mBAAU,GAAE;IACZ,IAAA,6BAAiB,EAAC,qCAAgB,CAAC;GACvB,0BAA0B,CAKtC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RoutingMessage } from '@nestjstools/messaging';
|
|
2
|
+
import { IMessageBus } from '@nestjstools/messaging';
|
|
3
|
+
import { AmazonSqsChannel } from '../channel/amazon-sqs.channel';
|
|
4
|
+
export declare class AmazonSqsMessageBus implements IMessageBus {
|
|
5
|
+
private readonly channel;
|
|
6
|
+
constructor(channel: AmazonSqsChannel);
|
|
7
|
+
dispatch(message: RoutingMessage): Promise<object | void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AmazonSqsMessageBus = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const amazon_sqs_channel_1 = require("../channel/amazon-sqs.channel");
|
|
15
|
+
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
16
|
+
let AmazonSqsMessageBus = class AmazonSqsMessageBus {
|
|
17
|
+
channel;
|
|
18
|
+
constructor(channel) {
|
|
19
|
+
this.channel = channel;
|
|
20
|
+
}
|
|
21
|
+
async dispatch(message) {
|
|
22
|
+
const command = new client_sqs_1.SendMessageCommand({
|
|
23
|
+
QueueUrl: this.channel.config.queueUrl,
|
|
24
|
+
MessageBody: JSON.stringify(message.message),
|
|
25
|
+
MessageAttributes: {
|
|
26
|
+
messagingRoutingKey: {
|
|
27
|
+
DataType: "String",
|
|
28
|
+
StringValue: message.messageRoutingKey,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
await this.channel.client.send(command);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.AmazonSqsMessageBus = AmazonSqsMessageBus;
|
|
36
|
+
exports.AmazonSqsMessageBus = AmazonSqsMessageBus = __decorate([
|
|
37
|
+
(0, common_1.Injectable)(),
|
|
38
|
+
__metadata("design:paramtypes", [amazon_sqs_channel_1.AmazonSqsChannel])
|
|
39
|
+
], AmazonSqsMessageBus);
|
|
40
|
+
//# sourceMappingURL=amazon-sqs-message.bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-sqs-message.bus.js","sourceRoot":"","sources":["../../src/message-bus/amazon-sqs-message.bus.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,2CAA4C;AAC5C,sEAAiE;AACjE,oDAAyD;AAGlD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEX;IADnB,YACmB,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAE5C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuB;QACpC,MAAM,OAAO,GAAG,IAAI,+BAAkB,CAAC;YACrC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;YACtC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;YAC5C,iBAAiB,EAAE;gBACjB,mBAAmB,EAAE;oBACnB,QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,OAAO,CAAC,iBAAiB;iBACvC;aACF;SACF,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;CACF,CAAA;AAnBY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAGiB,qCAAgB;GAFjC,mBAAmB,CAmB/B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MessagingAmazonSqsExtensionModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const amazon_sqs_messaging_consumer_1 = require("./consumer/amazon-sqs-messaging.consumer");
|
|
12
|
+
const amazon_sqs_channel_factory_1 = require("./channel/amazon-sqs.channel-factory");
|
|
13
|
+
const amazon_sqs_message_bus_factory_1 = require("./message-bus/amazon-sqs-message-bus-factory");
|
|
14
|
+
let MessagingAmazonSqsExtensionModule = class MessagingAmazonSqsExtensionModule {
|
|
15
|
+
};
|
|
16
|
+
exports.MessagingAmazonSqsExtensionModule = MessagingAmazonSqsExtensionModule;
|
|
17
|
+
exports.MessagingAmazonSqsExtensionModule = MessagingAmazonSqsExtensionModule = __decorate([
|
|
18
|
+
(0, common_1.Global)(),
|
|
19
|
+
(0, common_1.Module)({
|
|
20
|
+
providers: [
|
|
21
|
+
amazon_sqs_message_bus_factory_1.AmazonSqsMessageBusFactory,
|
|
22
|
+
amazon_sqs_channel_factory_1.AmazonSqsChannelFactory,
|
|
23
|
+
amazon_sqs_messaging_consumer_1.AmazonSqsMessagingConsumer,
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
], MessagingAmazonSqsExtensionModule);
|
|
27
|
+
//# sourceMappingURL=messaging-amazon-sqs-extension.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging-amazon-sqs-extension.module.js","sourceRoot":"","sources":["../src/messaging-amazon-sqs-extension.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,4FAAsF;AACtF,qFAA+E;AAC/E,iGAA0F;AAUnF,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;CAAG,CAAA;AAApC,8EAAiC;4CAAjC,iCAAiC;IAR7C,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,2DAA0B;YAC1B,oDAAuB;YACvB,0DAA0B;SAC3B;KACF,CAAC;GACW,iCAAiC,CAAG"}
|