@cnnrrss/replay-aws-dlq
Advanced tools
Comparing version 1.1.3 to 1.1.4
15
cli.js
@@ -27,4 +27,19 @@ #!/usr/bin/env node | ||
}) | ||
.option('maxAttempts', { | ||
type: 'number', | ||
description: | ||
'Maximum number of attempts to redrive the message in the destination queue.', | ||
default: 1 | ||
}) | ||
.option('messageAttributeNames', { | ||
alias: 'attrs', | ||
type: 'array', | ||
description: | ||
'List of message attributes to copy', | ||
default: [] | ||
}) | ||
.demandOption(['to', 'from']).argv; | ||
console.log(argv); | ||
if (require.main === module) { | ||
@@ -31,0 +46,0 @@ (async function() { |
@@ -108,2 +108,8 @@ const AWSMock = require('aws-sdk-mock'); | ||
'{"id":"5d31a25ae887bb000828e6f3","entityName":"photo","source":"gqes"}', | ||
MessageAttributes: { | ||
'replay-aws-dlq': { | ||
DataType: 'Number', | ||
StringValue: '1' | ||
} | ||
}, | ||
Id: '226052d0-5f52-4df8-91d2-53d58afdfc2c', | ||
@@ -125,2 +131,8 @@ MessageGroupId: 're-drive', | ||
'{"id":"5cdc0ae662fe4009f083f690","entityName":"photo","source":"gqin"}', | ||
MessageAttributes: { | ||
'replay-aws-dlq': { | ||
DataType: 'Number', | ||
StringValue: '1' | ||
} | ||
}, | ||
Id: '28cce3b3-003c-4920-9e11-e7904ee3f2c7', | ||
@@ -127,0 +139,0 @@ MessageGroupId: 're-drive', |
@@ -12,2 +12,4 @@ const pThrottle = require('p-throttle'); | ||
delay, | ||
maxAttempts, | ||
messageAttributeNames, | ||
options = { | ||
@@ -56,6 +58,34 @@ // To avoid the cost of establishing a new connection, reuse an existing connection by passing a new SQS instance with | ||
const handleMessage = async message => { | ||
const handleMessage = async ({ | ||
MessageId: id, | ||
MessageAttributes: messageAttributes, | ||
Body: body | ||
}) => { | ||
let messageRetries = 0; | ||
if (messageAttributes && messageAttributes['replay-aws-dlq']) { | ||
messageRetries = parseInt( | ||
messageAttributes['replay-aws-dlq'].StringValue, | ||
10 | ||
); | ||
} | ||
messageRetries += 1; | ||
if (messageRetries > maxAttempts) { | ||
throw new Error( | ||
`Number of retries ${messageRetries} exceeds max ${maxAttempts}` | ||
); | ||
} | ||
let payload = { | ||
id: message.MessageId, | ||
body: message.Body | ||
id, | ||
body, | ||
messageAttributes: { | ||
...messageAttributes, | ||
'replay-aws-dlq': { | ||
DataType: 'Number', | ||
StringValue: messageRetries.toString() | ||
} | ||
} | ||
}; | ||
@@ -76,5 +106,6 @@ | ||
groupId: 're-drive', | ||
deduplicationId: `${message.MessageId}_${Date.now()}` | ||
deduplicationId: `${id}_${Date.now()}` | ||
}; | ||
} | ||
await send(payload); | ||
@@ -87,3 +118,4 @@ count++; | ||
sqs, | ||
handleMessage | ||
handleMessage, | ||
messageAttributeNames | ||
}); | ||
@@ -90,0 +122,0 @@ |
{ | ||
"name": "@cnnrrss/replay-aws-dlq", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Re-drive dead letter queue messages to another queue", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
@@ -17,3 +17,8 @@ # replay-aws-dlq [![NPM version][npm-image]][npm-url] | ||
--to https://sqs.ap-southeast-2.amazonaws.com/718583902179/samstarter-v2-UploadAsset-1CF6W6RO07PGF \ | ||
--throttle 1 # throttle messages, in seconds, optional | ||
# throttle messages in seconds, optional | ||
--throttle 1 \ | ||
# maxAttempts to redrive from dlq to destination queue, default 1 | ||
--maxAttempts 1 \ | ||
# message attributes to copy, optional | ||
--attrs replay-aws-dlq another-one a-third-one | ||
``` | ||
@@ -20,0 +25,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13098
293
45