-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqs.js
96 lines (85 loc) · 2.21 KB
/
sqs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Load the AWS SDK for Node.js
var AWS = require("aws-sdk");
// Set the region
AWS.config.update({
accessKeyId: "test",
accessSecretKey: "test",
region: "ap-south-1",
});
// Create an SQS service object
var sqs = new AWS.SQS({
apiVersion: "2012-11-05",
endpoint: "http://localhost:4566",
});
const list = () => {
var params = {};
sqs.listQueues(params, function (err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.QueueUrls);
}
});
};
list();
const send = () => {
var params = {
// Remove DelaySeconds parameter and value for FIFO queues
// DelaySeconds: 10,
MessageAttributes: {
Title: {
DataType: "String",
StringValue: "The Whistler",
},
Author: {
DataType: "String",
StringValue: "John Grisham",
},
WeeksOn: {
DataType: "Number",
StringValue: "6",
},
},
MessageBody:
"Information about current NY Times fiction bestseller for week of 12/11/2016.",
// MessageDeduplicationId: "TheWhistler", // Required for FIFO queues
// MessageGroupId: "Group1", // Required for FIFO queues
QueueUrl: "http://localhost:4566/000000000000/localCheck",
};
sqs.sendMessage(params, function (err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.MessageId);
}
});
};
// send();
const recieveAndDelete = () => {
var params = {
AttributeNames: ["SentTimestamp"],
MaxNumberOfMessages: 10,
MessageAttributeNames: ["All"],
QueueUrl: "http://localhost:4566/000000000000/localCheck",
VisibilityTimeout: 20,
WaitTimeSeconds: 0,
};
sqs.receiveMessage(params, function (err, data) {
if (err) {
console.log("Receive Error", err);
} else if (data.Messages) {
var deleteParams = {
QueueUrl: "http://localhost:4566/000000000000/localCheck",
ReceiptHandle: data.Messages[0].ReceiptHandle,
};
sqs.deleteMessage(deleteParams, function (err, data) {
if (err) {
console.log("Delete Error", err);
} else {
console.log("Message Deleted", data);
}
});
}
});
};
// recieveAndDelete();