46
loading...
This website collects cookies to deliver better user experience
{
"containerDefinitions": [
{
"name": "[billing-address-service]",
"image": "[account-id].dkr.ecr.[region].amazonaws.com/[service-name]:[tag]",
"memoryReservation": "256",
"cpu": "256",
"essential": true,
"portMappings": [
{
"hostPort": "0",
"containerPort": "3000",
"protocol": "tcp"
}
]
}
],
"volumes": [],
"networkMode": "bridge",
"placementConstraints": [],
"family": "[billing-address-service]"
}
const { SQSClient, SendMessageCommand } = require("@aws-sdk/client-sqs");
const REGION = "us-west-1"; //replace with your region
const params = {
DelaySeconds: 12,
MessageAttributes: { // add other fields if you need them, remove what you don’t.
profileId: {
DataType: "Number",
StringValue: "543",
},
address: {
DataType: "String",
StringValue: "29 Acacia Road, Springfield",
},
},
MessageBody:
"Clothing Store Product Data.",
QueueUrl: "SQS_QUEUE_URL", // your queue URL
}
const sqs = new SQSClient({ region: REGION});
const run = async () => {
try {
const data = await sqs.send(new SendMessageCommand(params));
console.log("Success, product sent. MessageID:", data.MessageId);
} catch (err) {
console.log("Error", err);
}
};
run();
import { SQSClient } from "@aws-sdk/client-sqs";
const REGION = "us-west-1"; //replace with your region
const sqsClient = new SQSClient({ region: REGION });
export { sqsClient };
import {
ReceiveMessageCommand,
DeleteMessageCommand,
} from "@aws-sdk/client-sqs";
import { sqsClient } from "./libs/sqsClient.js";
// Set the parameters
const queueURL = "SQS_QUEUE_URL"; //Your queue URL
const params = {
AttributeNames: ["SentTimestamp"],
MaxNumberOfMessages: 10,
MessageAttributeNames: ["All"],
QueueUrl: queueURL,
VisibilityTimeout: 20,
WaitTimeSeconds: 0,
};
const run = async () => {
try {
const data = await sqsClient.send(new ReceiveMessageCommand(params));
if (data.Messages) {
var deleteParams = {
QueueUrl: queueURL,
ReceiptHandle: data.Messages[0].ReceiptHandle,
};
try {
// TODO: Save your data here
database.save(data);
// Then delete the queued message
const data = await sqsClient.send(new DeleteMessageCommand(deleteParams));
console.log("Message deleted", data);
} catch (err) {
console.log("Error", err);
}
} else {
console.log("No messages to delete");
}
return data; // For unit tests.
} catch (err) {
console.log("Receive Error", err);
}
};
run();
46