Node.js / NestJS

Queues with Bull

Bull queues, processors, jobs, delayed jobs, priority, retries, events

20 面接問題·
Mid-Level
1

What is Bull in the context of NestJS?

回答

Bull is a Node.js library for managing persistent queues based on Redis. It allows executing background tasks asynchronously, handling priorities, retries, and delayed jobs. NestJS provides a @nestjs/bull module that natively integrates Bull into the framework's modular architecture, making it easy to create workers and manage heavy or long-running jobs.

2

What is the role of a processor in Bull?

回答

A processor is a function that processes jobs from a queue. When a job is added to the queue, Bull automatically calls the corresponding processor to execute the business logic. The processor receives the job as a parameter and can access data via job.data. It can be synchronous or asynchronous and must return a value or Promise to signal job completion.

3

How to add a job to a Bull queue in NestJS?

回答

To add a job, inject the queue via @InjectQueue('queueName') then use the add() method. This method takes optional parameters: a job name, data to process (payload), and options like delay, priority, attempts. The method returns a Promise containing the created job with its unique ID, allowing tracking or manipulation later.

4

What is the function of Redis in Bull's architecture?

5

How to define a delayed job in Bull?

+17 面接問題

次の面接に向けてNode.js / NestJSをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める