Skip to content

Commit

Permalink
Merge pull request #2 from huangjimmy/issue_134_publish_to_sqs
Browse files Browse the repository at this point in the history
Fix mj1618#134  0.76.0: SNS -> publish to subscribed SQS queue, "Records" a…
  • Loading branch information
huangjimmy authored Feb 25, 2023
2 parents 1ea482c + 3935b5d commit d7a50fe
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/sns-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,14 @@ export class SNSServer implements ISNSServer {
const sqsEndpoint = `${subEndpointUrl.protocol}//${subEndpointUrl.host}/`;
const sqs = new SQS({ endpoint: sqsEndpoint, region: this.region });

if (sub["Attributes"]["RawMessageDelivery"] === "true") {
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: event,
MessageAttributes: formatMessageAttributes(messageAttributes),
...(messageGroupId && { MessageGroupId: messageGroupId }),
})
.promise();
} else {
const record = {
awsRegion: this.region,
eventSource: "aws:sqs",
body: event,
};
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: JSON.stringify({ Records: [record] }),
MessageAttributes: formatMessageAttributes(messageAttributes),
...(messageGroupId && { MessageGroupId: messageGroupId }),
})
.promise();
}
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: event,
MessageAttributes: formatMessageAttributes(messageAttributes),
...(messageGroupId && { MessageGroupId: messageGroupId }),
})
.promise();
}

public publish(
Expand Down

0 comments on commit d7a50fe

Please sign in to comment.