-
Notifications
You must be signed in to change notification settings - Fork 15
fixed SNS MessageAttributes parsing #94
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ export interface IMessageOpts { | |
| } | ||
|
|
||
| interface SNSBody { | ||
| MessageAttributes: string; | ||
| Message?: string; | ||
| Subject: string; | ||
| TopicArn: string; | ||
|
|
@@ -73,18 +74,19 @@ export class Message extends (EventEmitter as new() => MessageEmitter) { | |
| this._opts = opts; | ||
| this.raw = opts.msg; | ||
| this.body = opts.msg.Body; | ||
| this.attributes = parseMessageAttributes(opts.msg.MessageAttributes); | ||
| if (opts.unwrapSns) { | ||
| const unwrapped: SNSBody = JSON.parse(this.body || EMPTY_BODY); | ||
| this.body = unwrapped.Message; | ||
| this.subject = unwrapped.Subject; | ||
| this.topicArn = unwrapped.TopicArn; | ||
| this.attributes = parseMessageAttributes(unwrapped.MessageAttributes); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parseMessageAttributes expects a map and not a string
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also be aware that this will cause an overide of the real message attributes.... so if you send a regular message (not via SNS) this will remove all the attributes. Might be better to merge the attributes (_.extend() for example) |
||
| if (this.topicArn) { | ||
| this.topicName = unwrapped.TopicArn.substr(unwrapped.TopicArn.lastIndexOf(':') + 1); | ||
| } | ||
| } | ||
| this._squiss = opts.squiss; | ||
| this._handled = false; | ||
| this.attributes = parseMessageAttributes(opts.msg.MessageAttributes); | ||
| this.sqsAttributes = opts.msg.Attributes || {}; | ||
| this._s3Retriever = opts.s3Retriever; | ||
| this._s3Retain = opts.s3Retain; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,8 @@ export const parseMessageAttributes = (messageAttributes: SQS.MessageBodyAttribu | |
| }; | ||
|
|
||
| const parseAttributeValue = (unparsedAttribute: SQS.MessageAttributeValue): IMessageAttribute => { | ||
| const type = unparsedAttribute.DataType; | ||
| const stringValue = unparsedAttribute.StringValue; | ||
| const type = unparsedAttribute.DataType || unparsedAttribute.Type; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please parse according to the actual type using type guards
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @regevbr
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you give exampels please. I'm guessing that if you are using the raw option, you don't need the unwrapSns flag turned on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @regevbr
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, so lets try to handle it in this PR |
||
| const stringValue = unparsedAttribute.StringValue || unparsedAttribute.Value; | ||
| const binaryValue = unparsedAttribute.BinaryValue; | ||
|
|
||
| switch (type) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a proper typing for that and then use that interface in the parseMessageAttributes and related functions (please use type guards to parse properly depending on the type we receive)