Skip to content

Commit

Permalink
Merge pull request #55 from hpcc-systems/sqs-send-message
Browse files Browse the repository at this point in the history
Sqs send message
  • Loading branch information
martdo02 authored Oct 24, 2023
2 parents 529d6ad + 61cfb81 commit 54d9bba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 5 additions & 1 deletion packages/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ If a queue name is used, a regex search will be done to find the queue.

### `When {jsonObject} is sent to queue {string}`

Sends a new message to the SQS queue provided. `lastRun` will contain the message id and message
Sends a new message to the SQS queue name provided. The first queue that matches the provided name will be used. `lastRun` will contain the message id and message

### `When {jsonObject} is sent to queue url {string}`

Sends a new message to the SQS queue URL provided. `lastRun` will contain the message id and message

### `When the next message is received from queue {string}`

Expand Down
4 changes: 2 additions & 2 deletions packages/aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "2.2.0",
"version": "2.2.1",
"description": "AWS steps for MAF. This contains S3, DynamoDB, SQS, ECS, Cloudwatch, and Lambda stepDefinitions",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -39,5 +39,5 @@
"multiple-cucumber-html-reporter": "^3.5.0",
"nyc": "^15.1.0"
},
"gitHead": "9bf55a2c86fa17707fabfb4320c3d722e270f9e6"
"gitHead": "9c565ac48ddb32311b115a463c45625de3ff29e4"
}
29 changes: 22 additions & 7 deletions packages/aws/stepDefinitions/sqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ async function getURLfromQueueName (queueName) {
}

/**
* Sends a message to a queue
* Sends a message to a queue using only the queue name
* @param {JSON|String} message The message to send
* @param {String} QueueUrl The name of the queue to send the message to
* @param {String} QueueName The name of the queue to send the message to
* @returns {JSON} SendMessageCommandOutput (https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/interfaces/sendmessagecommandoutput.html)
*/
async function sendMessageToQueue (message, QueueUrl) {
if (!/^https?:\/\//.test(QueueUrl)) {
QueueUrl = await getURLfromQueueName(QueueUrl)
async function sendMessageToQueue (message, QueueName) {
let QueueUrl
if (!/^https?:\/\//.test(QueueName)) {
QueueUrl = await getURLfromQueueName(QueueName)
} else {
QueueUrl = QueueName
}
const queryParameters = { MessageBody: message, QueueUrl }
return await sqsClient.send(new SendMessageCommand(queryParameters))
Expand Down Expand Up @@ -108,13 +111,25 @@ MAFWhen('queue {string} is purged', async function (QueueUrl) {
MAFWhen('{jsonObject} is sent to queue {string}', async function (message, queue) {
message = performJSONObjectTransform.call(this, message)
queue = filltemplate(queue, this.results)
return await sendMessageToQueue(message, queue)
return sendMessageToQueue(message, queue)
})

MAFWhen('{jsonObject} is sent to queue url {string}', async function (message, QueueUrl) {
message = performJSONObjectTransform.call(this, message)
QueueUrl = filltemplate(QueueUrl, this.results)
return await sqsClient.send(new SendMessageCommand({ MessageBody: message, QueueUrl }))
})

MAFWhen('{string} message is sent to queue {string}', async function (message, queue) {
message = filltemplate(message, this.results)
queue = filltemplate(queue, this.results)
return await sendMessageToQueue(message, queue)
return sendMessageToQueue(message, queue)
})

MAFWhen('{string} message is sent to queue url {string}', async function (message, QueueUrl) {
message = filltemplate(message, this.results)
QueueUrl = filltemplate(QueueUrl, this.results)
return await sqsClient.send(new SendMessageCommand({ MessageBody: message, QueueUrl }))
})

MAFWhen('the next message is received from queue {string}', async function (queueURL) {
Expand Down

0 comments on commit 54d9bba

Please sign in to comment.