skip to Main Content

I am following doc to start to use queue. I installed @nestjs/bull, bull, @types/bull dependencies. And here is my app.module.ts:

@Module({
    imports: [
        ConfigModule.forRoot({
            load: [configuration],
        }),
        BullModule.registerQueue({
            name: 'create_checkin',
            redis: {
                host: 'localhost',
                port: 6379,
            },
        }),
        EventModule,
    ],
})
export class AppModule {}

I imported BullModule in root module. And here is my event.service.ts:

@Injectable()
export class EventService {

    constructor(
        @InjectQueue('create_checkin') private readonly createCheckinQueue: Queue,
    ) {
    }
}

And when I start server, I got the following error message:

Nest can't resolve dependencies of the EventService
Please make sure that the argument BullQueue_create_checkin at index [0] is available in the EventModule context.

I don’t know which step I did wrong. Someone can help me?

5

Answers


  1. Make sure you are placing EventService under providers array in EventModule.

    @Module({
         providers: [EventService],
         controllers :[],
         imports: [YOUR_MODULES],
         exports: [EventService]
    })
    export class EventModule {}
    
    Login or Signup to reply.
  2. Try importing BullModule straight in Event Module – I had the same problem and doing it this way make it work.

    @Module({
      imports: [
        BullModule.registerQueueAsync({
          name: 'csv',
          useFactory: async (config: ConfigService) => ({
            redis: config.get('redis'),
          }),
          inject: [ConfigService],
        }),
      ],
      providers: [
        CsvService
      ],
      exports: [CsvService],
    })
    export class CsvModule {}
    

    I know that it’s async method, but maybe you should try.

    Login or Signup to reply.
  3. You have to import bull module inside the module you are trying to setup queue. You can also refer https://medium.com/@shikhar01.cse14/bull-queues-in-nestjs-306c51cb0ec2

    Login or Signup to reply.
  4. Had a similar problem, in my case it was enough to add the BullModule to the exports array in order to successfully run the whole project. Like this:

    @Module({
      imports: [
        BullModule.registerQueue({ ... }),
        ...
      ],
      ...
      exports: [
        BullModule,  // <— this is important!
        ...
      ]
    })
    

    Then in my service I’ve been able to inject the queue:

    @InjectQueue('print') private queue: Queue<PrintJob>
    
    Login or Signup to reply.
  5. You can do like below

    @Module({
        imports: [
            ConfigModule.forRoot({
                load: [configuration],
            }),
            EventModule,
        ],
    })
    export class AppModule {}
    
    @Module({
        imports: [
            BullModule.registerQueue({
                name: 'create_checkin',
                redis: {
                    host: 'localhost',
                    port: 6379,
                },
            }),
        ],
    })
    export class EventModule {}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search