A highly scalable and efficient Task Queue system built with BullMQ, leveraging Redis as a backend for managing and processing background tasks. This system offers capabilities like task retries, delayed tasks, and a Dead-Letter Queue (DLQ) for tasks that fail after multiple retries.
- Asynchronous Task Processing: Handle heavy tasks in the background without blocking the main application flow.
- Retry Logic with Exponential Backoff: Automatically retry failed tasks with an increasing delay.
- Dead-Letter Queue (DLQ): Track and manage failed tasks that couldn't be processed after multiple retries.
- Delayed Tasks: Schedule tasks to be processed at a later time.
- API for Task Management: Add tasks to the queue, view tasks in the DLQ, and clear failed tasks from the DLQ.
- BullMQ: A powerful queue system for Node.js, with support for background jobs, retries, and scheduling.
- Redis: In-memory data store used as the backend for task management.
- Express.js: Web framework for building the API to interact with the task queue system.
- Node.js: JavaScript runtime for building the backend service.
To get started with this service, follow these steps:
First, you need to have Redis running on your system. Install Redis and start the server:
redis-serverClone the repository to your local machine:
git clone https://github.com/slowmoe17/task-queue-system.git
cd task-queue-systemInstall all required dependencies using npm:
npm installCreate a .env file in the root directory with the following content:
REDIS_HOST=127.0.0.1
REDIS_PORT=6379Run the server with the following command:
node src/server.jsThis will start the Express server on http://localhost:3000.
POST /api/tasks
Add a new task to the queue.
{
"type": "email", // Type of task (e.g., email, report-generation)
"payload": { // Data for processing
"recipient": "user@example.com",
"message": "Hello, World!"
},
"visibility_time": "2025-01-01T12:00:00Z" // Optional visibility time (when the task becomes eligible for processing)
}{
"id": "<task-id>",
"status": "Task added to queue"
}GET /api/dlq
Fetch tasks that failed after multiple retries.
[
{
"id": "<task-id>",
"type": "<task-type>",
"payload": {...},
"error": "<error-message>"
}
]DELETE /api/dlq
Remove all tasks from the DLQ.
{
"status": "DLQ cleared"
}