Skip to content
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ queue.pull('test', function(message, callback) {
callback(); // we are done with this message - pull a new one
// calling the callback will also delete the message from the queue
});
```
Use the following method add [SQS Message Attributes](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html) to the message
```js
// push data to the 'test' queue with the message body as {some:"data"}
// The message has 2 message attributes as {"category":"book","bookid":5492}
queue.pushWithAttributes('test', {
some:'data'
}, {
category: "book",
bookid: 5492
}, function() {
//complete
});

```

## API
Expand Down
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,33 @@ module.exports = function(options) {
});
};

that.pushWithAttributes = function(name, message, attributes, callback) {
//attributes like {"category":"book","bookid":5492}

message = options.raw ? message : JSON.stringify(message);

name = namespace + name;
var payload = {
MessageBody: message
};

var attributeNames = Object.keys(attributes);

//sqs accepts only 10 attributes
attributeNames.splice(10);

attributeNames.forEach(function(attributeName, index) {
var baseName = "MessageAttribute." + (index + 1);
payload[baseName + ".Name"] = attributeName;
payload[baseName + ".Value.StringValue"] = attributes[attributeName];
payload[baseName + ".Value.DataType"] = typeof attributes[attributeName] == "number" ? "Number" : "String";
})

queueURL(name, function(url) {
retry(request, queryURL('SendMessage', url, payload), callback);
});
};

that.delete = that.del = function(name, callback) {
name = namespace+name;

Expand Down