Task Queues
Queues are a powerful design pattern that can help you meet common application scaling and performance challenges. Some of the problems queues can help you solve.
Examples are as follows.
- Smoothing out peaks. You can start resource-intensive tasks at any time and then add them to a queue instead of executing them synchronously. Let task processes pull tasks from the queue in a controlled manner. It is also easy to add new queue consumers to extend back-end task processing.
- Decompose single tasks that might block the Node.js event loop. For example, if a user request requires CPU-intensive work like audio transcoding, this task can be delegated to another process, freeing up the user-facing process to maintain a response.
- Provide reliable communication channels across various services. For example, you can queue tasks (jobs) in one process or service and use them in another process or service. You can receive notifications (by listening for status events) when a job completes, errors, or other status changes during the job lifecycle of any process or service. When a queue producer or consumer fails, their state is retained and job processing can be automatically restarted when the node is restarted.
Midway provides the @midwayjs/bull package as an abstraction/wrapper on top of Bull, a popular, well-supported, high performance NPP-based application. well-supported, high-performance implementation of the Node.js-based queueing system. This package makes it easy to integrate Bull Queues into your application.
Bull uses Redis to hold job data, and when using Redis, the Queue architecture is fully distributed and platform independent. For example, you can run some Queue producers, consumers in one (or more) nodes (processes), and other producers and consumers on other nodes.
This chapter introduces the @midwayjs/bull package. We also recommend reading the Bull documentation for more background and implementation details.
-
- As of v3.6.0, the original task scheduling
@midwayjs/taskmodule is deprecated, so if you check the history documentation, please refer to [here](. /legacy/task).
- As of v3.6.0, the original task scheduling
-
- bull is a distributed task management system and must rely on redis
Related information.
| description | |
|---|---|
| Available for standard projects | ✅ |
| Available for Serverless | ❌ |
| Available for Integration | ✅ |
| Include standalone mainframe |