Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MessageAttributes #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/__tests__/replayAwsDlq.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ const mockMessages = [
MessageId: '226052d0-5f52-4df8-91d2-53d58afdfc2c',
Body:
'{"id":"5d31a25ae887bb000828e6f3","entityName":"photo","source":"gqes"}',
ReceiptHandle: 'receipt-handle-1'
ReceiptHandle: 'receipt-handle-1',
MessageAttributes: {
SomeImportantAttr: {
StringValue: 'foobar',
BinaryValue: null,
BinaryListValue: [],
StringListValue: [],
DataType: 'String'
}
}
},
{
MessageId: '28cce3b3-003c-4920-9e11-e7904ee3f2c7',
Expand Down Expand Up @@ -107,7 +116,13 @@ describe('redrive messages', () => {
'{"id":"5d31a25ae887bb000828e6f3","entityName":"photo","source":"gqes"}',
Id: '226052d0-5f52-4df8-91d2-53d58afdfc2c',
MessageGroupId: 're-drive',
MessageDeduplicationId: expect.any(String)
MessageDeduplicationId: expect.any(String),
MessageAttributes: {
SomeImportantAttr: {
DataType: 'String',
StringValue: 'foobar'
}
}
}
]
},
Expand All @@ -123,7 +138,8 @@ describe('redrive messages', () => {
'{"id":"5cdc0ae662fe4009f083f690","entityName":"photo","source":"gqin"}',
Id: '28cce3b3-003c-4920-9e11-e7904ee3f2c7',
MessageGroupId: 're-drive',
MessageDeduplicationId: expect.any(String)
MessageDeduplicationId: expect.any(String),
MessageAttributes: {}
}
]
},
Expand Down
16 changes: 14 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ const redrive = ({ from: sourceQueueUrl, to: destQueueUrl, options = {} }) => {
};

const handleMessage = async message => {
const messageAttributes = Object.entries(
message.MessageAttributes || {}
).reduce((sendMessageAttrs, [key, value]) => {
sendMessageAttrs[key] = {
StringValue: value.StringValue,
DataType: value.DataType
};
return sendMessageAttrs;
}, {});

let payload = {
id: message.MessageId,
body: message.Body
body: message.Body,
messageAttributes
};

// For FIFO queue we need to make sure this message is unique and is in correct order
Expand All @@ -49,7 +60,8 @@ const redrive = ({ from: sourceQueueUrl, to: destQueueUrl, options = {} }) => {
const source = Consumer.create({
queueUrl: sourceQueueUrl,
sqs,
handleMessage
handleMessage,
messageAttributeNames: ['All']
});

source.on('error', handleError);
Expand Down