Upload files to "elasticmq"
This commit is contained in:
parent
6cf88a6115
commit
54b348c1cd
3 changed files with 119 additions and 0 deletions
53
elasticmq/receive-test.ts
Normal file
53
elasticmq/receive-test.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import {
|
||||||
|
SQSClient,
|
||||||
|
ReceiveMessageCommand,
|
||||||
|
DeleteMessageCommand,
|
||||||
|
DeleteMessageBatchCommand,
|
||||||
|
ReceiveMessageCommandInput,
|
||||||
|
DeleteMessageCommandInput,
|
||||||
|
DeleteMessageBatchCommandInput
|
||||||
|
} from "@aws-sdk/client-sqs";
|
||||||
|
import { v4 as uuid } from "uuid";
|
||||||
|
import { SqsConfig } from "./sqs.config";
|
||||||
|
|
||||||
|
|
||||||
|
const client: SQSClient = new SQSClient(
|
||||||
|
{
|
||||||
|
region: SqsConfig.region,
|
||||||
|
endpoint: SqsConfig.endpoint,
|
||||||
|
credentials: SqsConfig.credentials,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const params: ReceiveMessageCommandInput = {
|
||||||
|
AttributeNames: ["SentTimestamp"],
|
||||||
|
MaxNumberOfMessages: 10,
|
||||||
|
MessageAttributeNames: ["All"],
|
||||||
|
QueueUrl: `${SqsConfig.endpoint}/${SqsConfig.accountId}/${SqsConfig.queueName}`,
|
||||||
|
VisibilityTimeout: 20,
|
||||||
|
WaitTimeSeconds: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const command: ReceiveMessageCommand = new ReceiveMessageCommand(params);
|
||||||
|
|
||||||
|
|
||||||
|
client.send(command).then((response) => {
|
||||||
|
if (response.Messages) {
|
||||||
|
console.log(JSON.stringify(response.Messages, null, 2));
|
||||||
|
const deleteParams: DeleteMessageBatchCommandInput = {
|
||||||
|
QueueUrl: `${SqsConfig.endpoint}/${SqsConfig.accountId}/${SqsConfig.queueName}`,
|
||||||
|
Entries: response.Messages.map((message) => ({
|
||||||
|
ReceiptHandle: message.ReceiptHandle,
|
||||||
|
Id: uuid(),
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
client.send(new DeleteMessageBatchCommand(deleteParams)).then(() => {
|
||||||
|
console.log("Message deleted");
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
42
elasticmq/send-test.ts
Normal file
42
elasticmq/send-test.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import { SQSClient, SendMessageCommand, SendMessageCommandInput } from "@aws-sdk/client-sqs";
|
||||||
|
import { v4 as uuid } from "uuid";
|
||||||
|
import { SqsConfig } from "./sqs.config";
|
||||||
|
|
||||||
|
const client: SQSClient = new SQSClient(
|
||||||
|
{
|
||||||
|
region: SqsConfig.region,
|
||||||
|
endpoint: SqsConfig.endpoint,
|
||||||
|
credentials: SqsConfig.credentials,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const params: SendMessageCommandInput = {
|
||||||
|
// DelaySeconds: 10, // remove when non FIFO
|
||||||
|
MessageAttributes: {
|
||||||
|
Title: {
|
||||||
|
DataType: "String",
|
||||||
|
StringValue: "Test message",
|
||||||
|
},
|
||||||
|
Author: {
|
||||||
|
DataType: "String",
|
||||||
|
StringValue: "Michal Adamski",
|
||||||
|
},
|
||||||
|
SomeNumberAttribute: {
|
||||||
|
DataType: "Number",
|
||||||
|
StringValue: "6",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MessageBody: "This is test message body for Engage SaySimple project",
|
||||||
|
MessageDeduplicationId: uuid(), // Required for FIFO queues
|
||||||
|
MessageGroupId: "Group1", // Required for FIFO queues
|
||||||
|
QueueUrl: `${SqsConfig.endpoint}/${SqsConfig.accountId}/${SqsConfig.queueName}` //SQS_QUEUE_URL; e.g., 'https://sqs.REGION.amazonaws.com/ACCOUNT-ID/QUEUE-NAME'
|
||||||
|
};
|
||||||
|
|
||||||
|
const command: SendMessageCommand = new SendMessageCommand(params);
|
||||||
|
|
||||||
|
|
||||||
|
client.send(command).then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
24
elasticmq/sqs.config.ts
Normal file
24
elasticmq/sqs.config.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import "dotenv/config";
|
||||||
|
|
||||||
|
export interface SqsConfig {
|
||||||
|
endpoint: string;
|
||||||
|
region: string;
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: string;
|
||||||
|
secretAccessKey: string;
|
||||||
|
};
|
||||||
|
queueName: string;
|
||||||
|
accountId: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SqsConfig: SqsConfig = {
|
||||||
|
endpoint: process.env.ENDPOINT ?? "http://localhost:9324",
|
||||||
|
region: process.env.REGION ?? "elasticmq",
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: process.env.ACCESS_KEY_ID ?? "x",
|
||||||
|
secretAccessKey: process.env.SECRET_ACCESS_KEY ?? "x",
|
||||||
|
},
|
||||||
|
queueName: process.env.QUEUE_NAME ?? "messages.fifo",
|
||||||
|
accountId: process.env.ACCOUNT_ID ?? "accountId",
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue