Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Fixed issue where error was thrown when message body is not JSON #10

Open
wants to merge 4 commits 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
10 changes: 8 additions & 2 deletions dist/sqs-queue-parallel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* sqs-queue-parallel 0.1.6 <https://github.com/bigluck/sqs-queue-parallel>
* sqs-queue-parallel 0.1.7 <https://github.com/bigluck/sqs-queue-parallel>
* Create a poll of Amazon SQS queue watchers and each one can receive 1+ messages
*
* Available under MIT license <https://github.com/bigluck/sqs-queue-parallel/raw/master/LICENSE>
Expand Down Expand Up @@ -74,9 +74,15 @@
console.log("SqsQueueParallel " + self.config.name + "[" + index + "]: " + queue.Messages.length + " new messages");
}
return async.eachSeries(queue.Messages, function(message, next) {
var data;
try {
data = JSON.parse(message.Body);
} catch (_error) {
data = message.Body;
}
return self.emit("message", {
type: 'message',
data: JSON.parse(message.Body) || message.Body,
data: data,
message: message,
metadata: queue.ResponseMetadata,
url: self.url,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "dist/sqs-queue-parallel",
"homepage": "https://github.com/bigluck/sqs-queue-parallel",
"author": "Luca Bigon",
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"licenses": [
{
Expand Down
6 changes: 5 additions & 1 deletion src/sqs-queue-parallel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ module.exports = class SqsQueueParallel extends events.EventEmitter
return next null unless queue.Messages?[0]
console.log "SqsQueueParallel #{ self.config.name }[#{ index }]: #{ queue.Messages.length } new messages" if self.config.debug
async.eachSeries queue.Messages, (message, next) ->
try
data = JSON.parse(message.Body)
catch
data = message.Body
self.emit "message",
type: 'message'
data: JSON.parse(message.Body) or message.Body
data: data
message: message
metadata: queue.ResponseMetadata
url: self.url
Expand Down