Run Queue Workers
Nest Queue provides a clean and maintaible API to manage message queues over several popular queue brokers like aws sqs, redis(coming soon), rabbitmq(coming soon).
note
You don't need to run QueueWorker if you are using sync
driver.
To perform action on any queue, you can make use of QueueWorker
class. To initialize,
Note that if any of the value is not passed, then default setting for the missing property will be used as fallback.
info
If you are using multiple queues/connections in your application, then you will have to run different queue worker instances for each queue/connection.
Functions
Run Listener
Now that we have created jobs and dispatched them, it is now necessary that we run the queue worker which will start pulling jobs from queues and process them.
Purge Queue
You may want to clear(purge) the queue, you can do so by calling clear
method.
Running
There are several ways through which you may want to run queue workers,
- via npm script
- [COMING SOON] custom cli commands (uses @squareboat/nest-console) internally.
via @squareboat/nest-console
The package already contains predefined commands to help you easily run the queue workers and other actions.
Following commands are supported out of the box
Command | Description |
---|---|
queue:work | Command to run the queue worker, starts processing the jobs |
queue:length | Command to get the length of the specified queue |
queue:purge | Command to purge the queue |
All the commands expect sleep
, queue
, connection
attributes. If none of the attributes are passed, default configurations options will be assumed.
To use these commands, you need to install @squareboat/nest-console
package and simply import the ConsoleModule
inside AppModule
.
info
For more information on various usage of @squareboat/nest-console
, you can read about it here.
Now, simply do
via npm script
You can simply create your own typescript script like below
Now, do the following change in your package.json
Similarly for the purge function as well, you can create different commands.