183d034716
Reorganizing by Feature sections Capabilities folders to give an overview of each feature How-Tos folders to give guidance for advanced customizations Reorganized the Developers section as well, moving the API sub section there added some new visuals and videos to illustrate the How-Tos articles checked the typos, the links and added a section at the end of the doc.json file to redirect existing links to the new ones (SEO purpose + continuity of the user experience) What I have not updated is the "l" folder that, per my understanding, contains the translation of the User Guide - that I only edited in English <!-- CURSOR_SUMMARY --> --- > [!NOTE] > <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is generating a summary for commit 5301502a32856e5b45d7ef30253fa7db6dc55233. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions@twenty.com> Co-authored-by: Abdul Rahman <ar5438376@gmail.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
---
|
|
title: Message Queue
|
|
---
|
|
|
|
|
|
Queues facilitate async operations to be performed. They can be used for performing background tasks such as sending a welcome email on register.
|
|
Each use case will have its own queue class extended from `MessageQueueServiceBase`.
|
|
|
|
Currently, we only support `bull-mq`[bull-mq](https://bullmq.io/) as the queue driver.
|
|
|
|
## Steps to create and use a new queue
|
|
|
|
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.
|
|
|
|
### Example usage
|
|
```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
|
|
});
|
|
}
|
|
}
|
|
```
|
|
|
|
|