SkillAgentSearch skills...

Wtsqs

Simplified Node AWS SQS Worker Wrapper

Install / Use

/learn @ali-essam/Wtsqs
About this skill

Quality Score

0/100

Category

Operations

Supported Platforms

Universal

README

WTSQS

npm version Build Status Coverage Status Dependencies Dev Dependencies

Simplified SQS Wrapper and Async Worker manager.

Features:

  • Simple interface. :white_check_mark:
  • Promise based. :white_check_mark:
  • ES6. :white_check_mark:
  • Optimized async worker. :white_check_mark:

Install

# Using npm
$ npm install wtsqs --save

# Or using yarn
$ yarn add wtsqs

Classes

<dl> <dt><a href="#WTSQS">WTSQS</a></dt> <dd><p>A simplified sqs wrapper with interface similar to a normal queue data structure.</p> </dd> <dt><a href="#WTSQSWorker">WTSQSWorker</a></dt> <dd><p>WTSQS worker job manager.</p> <p>WTSQSWorker takes care of asynchronously fetching jobs from sqs while processing other jobs concurrently. It also takes care of deleting a job from the queue after successfully processing the message.</p> </dd> </dl>

Typedefs

<dl> <dt><a href="#Message">Message</a> : <code>Object</code></dt> <dd><p>Received SQS Message</p> </dd> <dt><a href="#Job">Job</a> : <code>Object</code></dt> <dd><p>Worker Job</p> </dd> </dl>

<a name="WTSQS"></a>

WTSQS

A simplified sqs wrapper with interface similar to a normal queue data structure.

Kind: global class


<a name="new_WTSQS_new"></a>

new WTSQS(options)

Constructs WTSQS object.

| Param | Type | Default | Description | | --- | --- | --- | --- | | options | <code>Object</code> | | Options object. | | options.url | <code>String</code> | | SQS queue url. | | [options.accessKeyId] | <code>String</code> | | AWS access key id. | | [options.secretAccessKey] | <code>String</code> | | AWS secret access key. | | [options.region] | <code>String</code> | <code>us-east-1</code> | AWS regions where queue exists. | | [options.defaultMessageGroupId] | <code>String</code> | | FIFO queues only. Default tag assigned to a message that specifies it belongs to a specific message group. If not provided random uuid is assigned to each message which doesn't guarantee order but allows parallelism. | | [options.defaultVisibilityTimeout] | <code>Integer</code> | <code>60</code> | Default duration (in seconds) that the received messages are hidden from subsequent retrieve requests. | | [options.defaultPollWaitTime] | <code>Integer</code> | <code>10</code> | Default duration (in seconds) for which read calls wait for a message to arrive in the queue before returning. | | [options.sqsOptions] | <code>Object</code> | | Additional options to extend/override the underlying SQS object creation. |

Example

const { WTSQS } = require('wtsqs')

// The most simple way to construct a WTSQS object
const wtsqs = new WTSQS({
  url: '//queue-url',
  accessKeyId: 'AWS_ACCESS_KEY_ID',
  secretAccessKey: 'AWS_SECRET_ACCESS_KEY'
})

<a name="WTSQS+size"></a>

wtsqs.size() ⇒ <code>Promise.<integer></code>

Get approximate total number of messages in the queue.

Kind: instance method of <code>WTSQS</code>
Example

const size = await wtsqs.size()
console.log(size) // output: 2

<a name="WTSQS+enqueueOne"></a>

wtsqs.enqueueOne(payload, [options], [sqsOptions]) ⇒ <code>Promise</code>

Enqueue single payload in the queue.

Kind: instance method of <code>WTSQS</code>
See: SQS#sendMessage

| Param | Type | Default | Description | | --- | --- | --- | --- | | payload | <code>Object</code> | | JSON serializable object. | | [options] | <code>Object</code> | | Options. | | [options.messageGroupId] | <code>String</code> | | Message group id to override default id. | | [sqsOptions] | <code>Object</code> | <code>{}</code> | Additional options to extend/override the underlying SQS sendMessage request. |

Example

const myObj = { a: 1 }
await wtsqs.enqueueOne(myObj)

<a name="WTSQS+enqueueMany"></a>

wtsqs.enqueueMany(payloads, [options], [sqsOptions]) ⇒ <code>Promise</code>

Enqueue batch of payloads in the queue.

Kind: instance method of <code>WTSQS</code>
See: SQS#sendMessageBatch

| Param | Type | Default | Description | | --- | --- | --- | --- | | payloads | <code>Array.<Object></code> | | Array of JSON serializable objects. | | [options] | <code>Object</code> | | Options object. | | [options.messageGroupId] | <code>String</code> | | Message group id to override default id. | | [sqsOptions] | <code>Object</code> | <code>{}</code> | Additional options to extend/override the underlying SQS sendMessageBatch request. |

Example

const myObjList = [{ a: 1 }, { b: 3 }]
await wtsqs.enqueueMany(myObjList)

<a name="WTSQS+peekOne"></a>

wtsqs.peekOne([options], [sqsOptions]) ⇒ <code>Promise.<(Message|null)></code>

Retrieve single message without deleting it.

Kind: instance method of <code>WTSQS</code>
Returns: <code>Promise.<(Message|null)></code> - Message object or null if queue is empty.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [options] | <code>Object</code> | | Options object. | | [options.pollWaitTime] | <code>Integer</code> | | Duration (in seconds) for which read call waits for a message to arrive in the queue before returning. If no messages are available and the wait time expires, the call returns successfully with an empty list of messages. | | [options.visibilityTimeout] | <code>Integer</code> | | Duration (in seconds) that the received messages are hidden from subsequent retrieve requests. | | [sqsOptions] | <code>Object</code> | <code>{}</code> | Additional options to extend/override the underlying SQS receiveMessage request. |

Example

const myMessage = await wtsqs.peekOne()
console.log(myMessage)
// output:
{
  id: 'messageId',
  receiptHandle: 'messageReceiptHandle'
  md5: 'messageMD5',
  body: { a: 1 }
}

<a name="WTSQS+peekMany"></a>

wtsqs.peekMany([maxNumberOfMessages], [options], [sqsOptions]) ⇒ <code>Promise.<Array.<Message>></code>

Retrieve batch of messages without deleting them.

Kind: instance method of <code>WTSQS</code>
Returns: <code>Promise.<Array.<Message>></code> - Array of retrieved messages.
See: SQS#receiveMessage

| Param | Type | Default | Description | | --- | --- | --- | --- | | [maxNumberOfMessages] | <code>Number</code> | <code>10</code> | Maximum number of messages to retrieve. Must be between 1 and 10. | | [options] | <code>Object</code> | | Options object. | | [options.pollWaitTime] | <code>Integer</code> | | Duration (in seconds) for which read call waits for a message to arrive in the queue before returning. If no messages are available and the wait time expires, the call returns successfully with an empty list of messages. | | [options.visibilityTimeout] | <code>Integer</code> | | Duration (in seconds) that the received messages are hidden from subsequent retrieve requests. | | [sqsOptions] | <code>Object</code> | <code>{}</code> | Additional options to extend/override the underlying SQS receiveMessage request. |

Example

const myMessageList = await wtsqs.peekMany(2)
console.log(myMessageList)
// output:
[
 {
   id: 'messageId',
   receiptHandle: 'messageReceiptHandle'
   md5: 'messageMD5',
   body: { a: 1 }
 },
 {
   id: 'messageId',
   receiptHandle: 'messageReceiptHandle'
   md5: 'messageMD5',
   body: { b: 3 }
 }
]

<a name="WTSQS+deleteOne"></a>

wtsqs.deleteOne(message) ⇒ <code>Promise</code>

Delete single message from queue.

Kind: instance method of <code>WTSQS</code>
See: SQS#deleteMessage

| Param | Type | Description | | --- | --- | --- | | message | <code>Message</code> | Message to be deleted |

Example

const myMessage = await wtsqs.peekOne()
await wtsqs.deleteOne(myMessage)

<a name="WTSQS+deleteMany"></a>

wtsqs.deleteMany(messages) ⇒ <code>Promise</code>

Delete batch of messages from queue.

Kind: instance method of <code>WTSQS</code>
See: SQS#deleteMessageBatch

| Param | Type |

View on GitHub
GitHub Stars17
CategoryOperations
Updated8mo ago
Forks3

Languages

JavaScript

Security Score

87/100

Audited on Jul 8, 2025

No findings