I have written the following API to recieve message :
app.get('/receive', function(req, res) {
var params = {
QueueUrl: queueUrl,
VisibilityTimeout: 600
};
sqs.receiveMessage(params, function(err, data) {
if (err) {
res.send(err);
} else {
console.log('data is ' + JSON.stringify(data));
res.send(data);
}
});
});
The response that I get is as follows:
{
"ResponseMetadata": {
"RequestId": "id"
},
"Messages": [
{
"MessageId": "id",
"ReceiptHandle": "handle",
"MD5OfBody": "body",
"Body": "body"
}
]
}
.
the send message format for the API is as shown below:
let params = {
MessageBody: object,
QueueUrl: process.env.queueUrl,
MessageAttributes:{
"Title":{
DataType:'String',
StringValue:'Item Id Array',
}
},
DelaySeconds: 0
}
sqs.send(params, (err, data) => {
console.log('------------the send message data is------------',err,data);
});
You must tell SQS which attributes you want to receive in the params passed to receiveMessage
function.
So in your case params
definition in /receive
route may look like this:
var params = {
QueueUrl: queueUrl,
VisibilityTimeout: 600,
MessageAttributeNames: ["All"],
};
Check out the following links for more info: