@cobee/queue
v1.1.7
Published
The simplest queue abstraction
Downloads
1,115
Readme
@cobee/queue
Just a queue abstraction library with a minimalist approach.
Installation
From Git
npm install [email protected]:cobee/payments/queue-client.git
From private registry
🚧 Not yet
Documentation
SQS
import { SQSClient } from '@aws-sdk/client-sqs';
import { SQS, QueueConfig } from '@cobee/queue';
interface MyPayload {
id: string;
timestamp: number;
}
const getId = () => Math.random().toString(15).substr(2);
async function main() {
const sqsClient = new SQSClient({
endpoint: AWS_ENDPOINT,
region: AWS_REGION,
credentials: {
accessKeyId: String(AWS_ACCESS_KEY_ID),
secretAccessKey: String(AWS_SECRET_ACCESS_KEY),
},
});
const config: Partial<QueueConfig> = {
partitionKey: (job) => String(job.id),
queueGroup: () => '*',
};
const sqs = new SQS<MyPayload>(QUEUE_URI, sqsClient, config);
setInterval(() => sqs.enqueue({ id: getId(), timestamp: Date.now() }), 1e3);
for await (const msg of sqs.consumer().start()) {
console.log(msg);
}
}
main();
Examples
There're some examples here to check how library works.
TODO
- [ ] Able to send error messages
- [ ] Abstraction layer for job handling
- [ ] Testing