---
title: メッセージキュー
image: /images/user-guide/emails/emails_header.png
---
キューは非同期処理を実行するための手段を提供します。 それらは、登録時にウェルカムメールを送信するなどのバックグラウンドタスクを実行するために使用できます。
各ユースケースには `MessageQueueServiceBase` から拡張された独自のキュークラスが必要です。
現在のところ、キュードライバとして `bull-mq`[bull-mq](https://bullmq.io/) のみをサポートしています。
## 新しいキューを作成して使用する手順
1. Add a queue name for your new queue under enum `MESSAGE_QUEUES`.
2. 依存トークンとしてキュー名を持つキューのファクトリ実装を提供します。
3. Inject the queue that you created in the required module/service with the queue name as the dependency token.
4. トークンベースのインジェクションを用いたワーカークラスをプロデューサーと同様に追加します。
### 使用例
```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
});
}
}
```