I’m building a application using BullMQ and NestJS. It’s all working fine, but there is something bugging me.
When register a new queue on my application I do something like that:
@Module({
imports: [
BullModule.registerQueueAsync({
name: 'email-queue',
}),
],
controllers: [EmailController],
providers: [ ],
})
Then, when I’m using it on a NestJS service, I’d do something like that:
@Injectable()
export class WhatsappQueueService {
constructor(
@InjectQueue('email-queue') private queue: Queue,
) {}
async addMessage(dtoSendMessage: any) {
const included = await this.queue.add(
'send-message',
dtoSendMessage,
);
return included;
}
}
The problem is that I’d like to create a constant with the value ’email-queue’, export it from the service and use it on the Module definition. So, I don’t have to manually manage the queue names.
When I use the constant, I get a error saying that NestJS can’t find the Queue. I believe that’s something to do with the @InjectQueue() decorator.
How can I use constants to name my queues?