Reputation: 809
I have 2 Nodejs services that communicate using Bullmq with each other. Unfortunately, the processor function is not invoked and all the messages lie as waiting in the queue as I check with Bullboard. However, I could not found the reason because TestConsumer
is in the providers
list of the ÀppModule`. I appreciate any help.
App module
import { Module } from '@nestjs/common';
import { AppService } from './app.service';
import { BullModule, InjectQueue } from '@nestjs/bull';
import { TestConsumer } from './queue/test.consumer';
import { Queue } from 'bull';
@Module({
imports: [
BullModule.forRoot({
redis: {
host: 'localhost',
port: 6379,
},
}),
BullModule.registerQueue({
name: 'test',
url: 'redis://localhost:6379',
}),
],
providers: [TestConsumer, AppService],
})
export class AppModule {
constructor(@InjectQueue('test') private testQueue: Queue) {
this.testQueue.getJobCounts().then(console.log);
}
}
And consumer
import { OnQueueActive, Process, Processor } from '@nestjs/bull';
import { Job } from 'bull';
@Processor('test')
export class TestConsumer {
@OnQueueActive()
onActive(job: Job) {
console.log(
`Processing job ${job.id} of type ${job.name} with data ${job.data}...`,
);
}
@Process()
async process(job: Job): Promise<void> {
console.log('Processing job');
const jobData = job.data;
console.log('Processing job', jobData);
}
}
I could not get any logs from the process function.
Upvotes: 1
Views: 648
Reputation: 1
Did you first add a job to the testQueue
in the app module, e.g in the app module constructor:
constructor(@InjectQueue('test') private testQueue: Queue) {
this.testQueue.add({ foo: 'bar'})
this.testQueue.getJobCounts().then(console.log);
}
Upvotes: 0