A queue consumer, also called a processor, is a function or class method that listens for jobs in a queue and processes them one by one. It handles tasks asynchronously outside the main app flow.
Click to reveal answer
beginner
How do you define a queue processor in NestJS?
You create a class decorated with @Processor('queueName') and add methods decorated with @Process() to handle jobs from that queue.
Click to reveal answer
beginner
What decorator marks a method as a job handler in a NestJS queue processor?
The @Process() decorator marks a method to handle jobs from the queue. It can take a job name to handle specific job types.
Click to reveal answer
beginner
Why use queue consumers in an application?
Queue consumers let you run slow or heavy tasks in the background, so the main app stays fast and responsive. They help with scaling and reliability.
Click to reveal answer
intermediate
How does NestJS handle job failures in queue processors?
NestJS allows retrying failed jobs automatically and provides hooks to catch errors in processors to log or handle failures gracefully.
Click to reveal answer
Which decorator is used to define a queue processor class in NestJS?
A@Processor('queueName')
B@QueueConsumer()
C@QueueHandler()
D@ProcessQueue()
✗ Incorrect
The @Processor('queueName') decorator marks a class as a queue processor for the specified queue.
What does the @Process() decorator do in a NestJS queue processor?
ACreates a new queue
BSchedules a job to run later
CDefines a method to process jobs from the queue
DStops the queue processing
✗ Incorrect
The @Process() decorator marks a method that will handle jobs pulled from the queue.
Why are queue consumers useful in web applications?
AThey automatically update the UI
BThey make the app run tasks in the background without blocking user requests
CThey replace the need for a web server
DThey speed up the database queries
✗ Incorrect
Queue consumers run heavy or slow tasks in the background, keeping the app responsive.
How can you handle different job types in one NestJS queue processor?
ANestJS does not support multiple job types
BCreate multiple processors for each job type
CUse @Processor() multiple times in one class
DUse multiple @Process() methods with job names
✗ Incorrect
You can define multiple @Process('jobName') methods in one processor class to handle different job types.
What happens if a job fails in a NestJS queue processor?
AIt can be retried automatically or handled in error hooks
BThe whole queue stops processing
CThe job is deleted without retry
DNestJS crashes
✗ Incorrect
NestJS supports retrying failed jobs and lets you catch errors to handle them properly.
Explain how to create a queue consumer (processor) in NestJS and how it processes jobs.
Think about how NestJS listens and handles jobs from a queue.
You got /4 concepts.
Describe why queue consumers are important in web applications and how NestJS supports error handling in them.
Consider user experience and reliability.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a queue consumer (processor) in a NestJS application?
easy
A. To send HTTP requests to external APIs
B. To render UI components on the client side
C. To listen to a queue and process jobs asynchronously in the background
D. To manage database migrations synchronously
Solution
Step 1: Understand the role of queue consumers
Queue consumers listen to queues and handle jobs asynchronously, allowing background processing.
Step 2: Compare with other options
Sending HTTP requests, rendering UI, and managing migrations are unrelated to queue consumers.
Final Answer:
To listen to a queue and process jobs asynchronously in the background -> Option C
Quick Check:
Queue consumer = background job handler [OK]
Hint: Queue consumers handle background jobs, not UI or HTTP [OK]
Common Mistakes:
Confusing queue consumers with HTTP controllers
Thinking queue consumers run synchronously
Assuming queue consumers manage UI rendering
2. Which decorator is used to mark a class as a queue consumer (processor) in NestJS?
easy
A. @Processor
B. @Queue
C. @Process
D. @Consumer
Solution
Step 1: Identify the decorator for queue consumers
The @Processor decorator marks a class as a queue consumer in NestJS.
Step 2: Differentiate from other decorators
@Process marks methods, @Queue and @Consumer are not valid NestJS decorators for this purpose.
Final Answer:
@Processor -> Option A
Quick Check:
Class decorator for consumers = @Processor [OK]
Hint: Class decorator for consumers is @Processor, method decorator is @Process [OK]
Common Mistakes:
Using @Process on the class instead of methods
Confusing @Processor with @Queue
Assuming @Consumer is a valid decorator
3. Given the following NestJS queue consumer code, what will be logged when a job with data { name: 'Alice' } is processed?
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';
@Processor('email')
export class EmailProcessor {
@Process('send')
async handleSend(job: Job) {
console.log(`Sending email to ${job.data.name}`);
}
}
medium
A. No output because handleSend is not called
B. Sending email to Alice
C. Error: job.data is not defined
D. Sending email to undefined
Solution
Step 1: Understand job data usage
The job object contains data with a name property 'Alice'. The method logs this value.
Step 2: Confirm method is called on 'send' jobs
The @Process('send') decorator ensures handleSend runs for jobs named 'send' in the 'email' queue.
Final Answer:
Sending email to Alice -> Option B
Quick Check:
job.data.name = 'Alice' logged correctly [OK]
Hint: Job data is accessed via job.data inside @Process methods [OK]
Common Mistakes:
Assuming job.data is undefined
Thinking method won't run without explicit call
Confusing queue name with job name
4. Identify the error in this NestJS queue consumer code snippet:
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';
@Processor('notifications')
export class NotificationProcessor {
@Process()
async handleNotification(job: Job) {
console.log('Notification:', job.data.message);
}
}
medium
A. Job parameter type should be any, not Job
B. The class should not have @Processor decorator
C. Console.log syntax is incorrect
D. @Process decorator is missing the job name argument
Solution
Step 1: Check @Process decorator usage
@Process requires a job name string to specify which jobs to handle; it's missing here.
Step 2: Validate other parts
@Processor on class is correct, Job type is valid, console.log syntax is correct.
Final Answer:
@Process decorator is missing the job name argument -> Option D
Quick Check:
@Process needs job name argument [OK]
Hint: @Process must specify job name string inside parentheses [OK]
Common Mistakes:
Omitting job name in @Process decorator
Removing @Processor from class
Changing Job type unnecessarily
5. You want to create a NestJS queue consumer that processes two different job types: 'email' and 'sms' in the same queue 'notifications'. Which is the correct way to define the processor class and methods?
hard
A. Use @Processor('notifications') on class, and two methods with @Process('email') and @Process('sms') decorators
B. Use two separate classes each with @Processor('notifications') and one @Process method
C. Use @Processor('email') and @Processor('sms') on the same class with one @Process method
D. Use @Process('notifications') on methods without @Processor on class
Solution
Step 1: Understand queue and job type separation
The queue is 'notifications'. The job types are 'email' and 'sms'. One class can handle multiple job types with separate @Process decorators.
Step 2: Validate correct decorator usage
@Processor('notifications') marks the queue. Methods use @Process('email') and @Process('sms') to handle each job type.
Final Answer:
Use @Processor('notifications') on class, and two methods with @Process('email') and @Process('sms') decorators -> Option A
Quick Check:
One class, multiple @Process methods for job types [OK]
Hint: One @Processor class can have many @Process methods for different jobs [OK]
Common Mistakes:
Creating multiple classes for same queue unnecessarily
Using multiple @Processor decorators on one class
Omitting @Processor on class and only using @Process
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.