ac-sqs 3.1.2 → 3.2.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/CHANGELOG.md +14 -0
- package/index.js +62 -7
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
# [3.2.0](https://github.com/admiralcloud/ac-sqs/compare/v3.1.2..v3.2.0) (2025-05-11 11:56:57)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Feature
|
|
6
|
+
|
|
7
|
+
* **App:** Add sendMessageBatch function | MP | [996482f316a4220d6486df6e83a19b9e63a832f0](https://github.com/admiralcloud/ac-sqs/commit/996482f316a4220d6486df6e83a19b9e63a832f0)
|
|
8
|
+
Add sendMessageBatch function
|
|
9
|
+
Related issues: [admiralcloud/ac-sqs#1](https://github.com/admiralcloud/ac-sqs/issues/1) [admiralcloud/ac-api-server#340](https://github.com/admiralcloud/ac-api-server/issues/340)
|
|
10
|
+
### Chores
|
|
11
|
+
|
|
12
|
+
* **App:** Updated packages | MP | [792e1b3ec19ee222242c07a3db7694a1f79c223f](https://github.com/admiralcloud/ac-sqs/commit/792e1b3ec19ee222242c07a3db7694a1f79c223f)
|
|
13
|
+
Updated packages
|
|
14
|
+
Related issues: [admiralcloud/ac-sqs#1](https://github.com/admiralcloud/ac-sqs/issues/1) [admiralcloud/ac-api-server#340](https://github.com/admiralcloud/ac-api-server/issues/340)
|
|
1
15
|
|
|
2
16
|
## [3.1.2](https://github.com/admiralcloud/ac-sqs/compare/v3.1.1..v3.1.2) (2025-04-23 07:40:43)
|
|
3
17
|
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
const { v4: uuidV4 } = require('uuid')
|
|
3
3
|
|
|
4
|
-
const { SQSClient, SendMessageCommand, ReceiveMessageCommand, DeleteMessageBatchCommand, GetQueueAttributesCommand, ChangeMessageVisibilityCommand } = require('@aws-sdk/client-sqs')
|
|
4
|
+
const { SQSClient, SendMessageCommand, SendMessageBatchCommand, ReceiveMessageCommand, DeleteMessageBatchCommand, GetQueueAttributesCommand, ChangeMessageVisibilityCommand } = require('@aws-sdk/client-sqs')
|
|
5
5
|
const { S3Client, GetObjectCommand, PutObjectCommand, DeleteObjectsCommand } = require("@aws-sdk/client-s3")
|
|
6
6
|
|
|
7
7
|
|
|
@@ -69,7 +69,7 @@ class ACSQS {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
async sendSQSMessage({ name, message, messageGroupId, deDuplicationId, delay, throwError }) {
|
|
72
|
+
async sendSQSMessage({ name, message, messageGroupId, deDuplicationId, delay, throwError, debug }) {
|
|
73
73
|
const config = _.find(this.availableLists, { name })
|
|
74
74
|
if (!config) {
|
|
75
75
|
this.logger.error('AWS | sendSQSMessage | configurationMissing | %s', name)
|
|
@@ -98,7 +98,7 @@ class ACSQS {
|
|
|
98
98
|
if (deDuplicationId) _.set(sqsParams, 'MessageDeduplicationId', deDuplicationId)
|
|
99
99
|
if (delay) _.set(sqsParams, 'DelaySeconds', delay)
|
|
100
100
|
|
|
101
|
-
if (config.debug) this.logger.debug('ACSQS | sendSQSMessage | Payload %j', sqsParams)
|
|
101
|
+
if (debug || config.debug) this.logger.debug('ACSQS | sendSQSMessage | Payload %j', sqsParams)
|
|
102
102
|
const command = new SendMessageCommand(sqsParams)
|
|
103
103
|
try {
|
|
104
104
|
const response = await this.sqs.send(command)
|
|
@@ -110,6 +110,61 @@ class ACSQS {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
async sendSQSMessageBatch({ name, messages, messageGroupId, deDuplicationId, delay, throwError, debug }) {
|
|
114
|
+
const config = _.find(this.availableLists, { name })
|
|
115
|
+
if (!config) {
|
|
116
|
+
this.logger.error('AWS | sendSQSMessageBatch | configurationMissing | %s', name)
|
|
117
|
+
throw new Error('configurationForListMissing')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const processedMessages = await Promise.all(
|
|
121
|
+
messages.map(async (message) => {
|
|
122
|
+
let messageBody = message
|
|
123
|
+
if (this.useS3 && message.length > this.messageThreshold) {
|
|
124
|
+
// store message in S3
|
|
125
|
+
const key = uuidV4()
|
|
126
|
+
const input = {
|
|
127
|
+
Bucket: this.bucket,
|
|
128
|
+
Key: key,
|
|
129
|
+
ContentType: 'text/plain',
|
|
130
|
+
Body: Buffer.from(message, 'utf-8')
|
|
131
|
+
}
|
|
132
|
+
const command = new PutObjectCommand(input)
|
|
133
|
+
await this.s3.send(command)
|
|
134
|
+
messageBody = `s3:${key}`
|
|
135
|
+
}
|
|
136
|
+
return messageBody
|
|
137
|
+
})
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
const entries = processedMessages.map((messageBody, index) => {
|
|
141
|
+
const item = {
|
|
142
|
+
Id: String(index),
|
|
143
|
+
MessageBody: messageBody
|
|
144
|
+
}
|
|
145
|
+
if (messageGroupId) item.MessageGroupId = messageGroupId
|
|
146
|
+
if (deDuplicationId) item.MessageDeduplicationId = `${deDuplicationId}-${index}`
|
|
147
|
+
if (delay) item.DelaySeconds = delay
|
|
148
|
+
return item
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
const sqsParams = {
|
|
152
|
+
QueueUrl: await this.getQueueUrl(config),
|
|
153
|
+
Entries: entries
|
|
154
|
+
}
|
|
155
|
+
if (debug || config.debug) this.logger.error('ACSQS | sendSQSMessageBatch | Payload %j', sqsParams)
|
|
156
|
+
|
|
157
|
+
const command = new SendMessageBatchCommand(sqsParams)
|
|
158
|
+
try {
|
|
159
|
+
const response = await this.sqs.send(command)
|
|
160
|
+
return response
|
|
161
|
+
}
|
|
162
|
+
catch(e) {
|
|
163
|
+
this.logger.error('ACSQS | sendSQSMessageBatch | %s | %s', name, e?.message)
|
|
164
|
+
if (this.throwError || throwError) throw e
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
113
168
|
async extendVisibility({ name, message, throwError }) {
|
|
114
169
|
const config = _.find(this.availableLists, { name })
|
|
115
170
|
if (!config) {
|
|
@@ -166,7 +221,7 @@ class ACSQS {
|
|
|
166
221
|
}
|
|
167
222
|
}
|
|
168
223
|
|
|
169
|
-
async receiveSQSMessages({ name, throwError }) {
|
|
224
|
+
async receiveSQSMessages({ name, throwError, debug }) {
|
|
170
225
|
const config = _.find(this.availableLists, { name })
|
|
171
226
|
if (!config) {
|
|
172
227
|
this.logger.error('ACSQS | receiveSQSMessage | configurationMissing | %s', name)
|
|
@@ -180,7 +235,7 @@ class ACSQS {
|
|
|
180
235
|
VisibilityTimeout: _.get(config, 'visibilityTimeout', 30),
|
|
181
236
|
WaitTimeSeconds: _.get(config, 'waitTime', 20)
|
|
182
237
|
}
|
|
183
|
-
if (config.debug) this.logger.debug('ACSQS | receiveSQSMessages | Payload %j', sqsParams)
|
|
238
|
+
if (debug || config.debug) this.logger.debug('ACSQS | receiveSQSMessages | Payload %j', sqsParams)
|
|
184
239
|
const command = new ReceiveMessageCommand(sqsParams)
|
|
185
240
|
try {
|
|
186
241
|
const result = await this.sqs.send(command)
|
|
@@ -230,7 +285,7 @@ class ACSQS {
|
|
|
230
285
|
}
|
|
231
286
|
|
|
232
287
|
// items -> [{ Id, ReceiptHandle }]
|
|
233
|
-
async deleteSQSMessages({ name, items, throwError }) {
|
|
288
|
+
async deleteSQSMessages({ name, items, throwError, debug }) {
|
|
234
289
|
const config = _.find(this.availableLists, { name })
|
|
235
290
|
if (!config) {
|
|
236
291
|
this.logger.error('AWS | deleteSQSMessage | configurationMissing | %s', name)
|
|
@@ -260,7 +315,7 @@ class ACSQS {
|
|
|
260
315
|
QueueUrl: await this.getQueueUrl(config),
|
|
261
316
|
Entries: entries
|
|
262
317
|
}
|
|
263
|
-
if (config.debug) this.logger.debug('ACSQS | deleteSQSMessages | Payload %j', sqsParams)
|
|
318
|
+
if (debug || config.debug) this.logger.debug('ACSQS | deleteSQSMessages | Payload %j', sqsParams)
|
|
264
319
|
const command = new DeleteMessageBatchCommand(sqsParams)
|
|
265
320
|
try {
|
|
266
321
|
const response = await this.sqs.send(command)
|
package/package.json
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "admiralcloud/ac-sqs",
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.2.0",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@aws-sdk/client-s3": "^3.
|
|
9
|
-
"@aws-sdk/client-sqs": "^3.
|
|
8
|
+
"@aws-sdk/client-s3": "^3.806.0",
|
|
9
|
+
"@aws-sdk/client-sqs": "^3.806.0",
|
|
10
10
|
"lodash": "^4.17.21",
|
|
11
11
|
"uuid": "^11.1.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"ac-semantic-release": "^0.4.6",
|
|
15
15
|
"chai": "^4.5.0",
|
|
16
|
-
"eslint": "^9.
|
|
16
|
+
"eslint": "^9.26.0",
|
|
17
17
|
"mocha": "^11.2.2"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|