Performance: Queue producers
This affects how fast messages are sent to the queue and how it impacts server responsiveness and resource usage.
sendMessage(data) {
this.queueClient.send(data).subscribe();
// fire-and-forget, non-blocking
}async sendMessage(data) { await this.queueClient.send(data).toPromise(); // waits for confirmation before continuing }
| Pattern | Event Loop Blocking | Throughput | Resource Usage | Verdict |
|---|---|---|---|---|
| Synchronous await per message | High (blocks event loop) | Low (sequential) | Moderate | [X] Bad |
| Fire-and-forget async send | Low (non-blocking) | High (parallel) | Low | [OK] Good |
sendEmail() is called?async sendEmail() {
await this.emailQueue.add('send_email', { to: 'user@example.com' });
return 'Email task added';
}@Injectable()
export class NotificationProducer {
constructor(@InjectQueue('notifications') private notificationsQueue: Queue) {}
async sendNotification(data: any) {
this.notificationsQueue.add('notify', data);
}
}Pass the test and this pattern moves unknown