--- title: Cua de Missatges image: /images/user-guide/emails/emails_header.png --- Header Les cues faciliten la realització d'operacions asíncrones. Es poden utilitzar per realitzar tasques en segon pla com enviar un correu de benvinguda en registrar-se. Cada cas d'ús tindrà la seva pròpia classe de cua estesa de `MessageQueueServiceBase`. Actualment, només admetem `bull-mq`[bull-mq](https://bullmq.io/) com a controlador de cua. ## Passos per crear i utilitzar una nova cua 1. Add a queue name for your new queue under enum `MESSAGE_QUEUES`. 2. Provide the factory implementation of the queue with the queue name as the dependency token. 3. Inject the queue that you created in the required module/service with the queue name as the dependency token. 4. Add worker class with token based injection just like producer. ### Exemple d'ús ```ts class Resolver { constructor(@Inject(MESSAGE_QUEUES.custom) private queue: MessageQueueService) {} async onSomeAction() { //business logic await this.queue.add(someData); } } //async worker class CustomWorker { constructor(@Inject(MESSAGE_QUEUES.custom) private queue: MessageQueueService) { this.initWorker(); } async initWorker() { await this.queue.work(async ({ id, data }) => { //worker logic }); } } ```