NestJS integration
Configure queues, Redis instances, endpoint capabilities, and async registration with @queuebert/nest.
Module options#
Import QueuebertModule from @queuebert/nest. Register once in the application that owns access to your queues.
| Option | Default | Purpose |
|---|---|---|
queues | Required | Queues to expose, each with a BullMQ name. |
path | admin/queue | Controller base path, without a leading slash. |
auth | None | Application-owned guards and controller class decorators. |
endpoints | ['metrics'] | Optional capabilities. stats is always enabled. |
includeRedisStats | true | Include Redis memory and connection statistics. |
redis | Inferred from the first queue | Named Redis instances for multi-Redis monitoring and migration. |
jobTypeDiscovery | Enabled, sample size 100, threshold 1000 | Discover job names and counts; large queues use sampling. |
includeJobDataInMigrationPreview | false | Include raw payloads in migration previews. Treat as sensitive. |
integrations | Automatic Nest package registration | Additional integration package metadata in stats. |
An explicit endpoints: [] exposes statistics only. Adding 'pause', 'resume', 'clean', 'drain', or 'migrations' enables that capability. Disabled capabilities return HTTP 404.
Queue configuration#
Each entry's name must match the BullMQ queue name. By default, Queuebert resolves queues registered through Nest's BullModule.
processor: optional class implementingQueuebertProcessor, registered as a Nest provider. Use BaseQueueProcessor for the built-in implementation.statsKey: a unique response and operation key, defaulting toname. Give same-named queues on different Redis instances distinct keys.redis: the ID of an entry in the module'sredisarray.queue: a direct BullMQQueueinstance instead of a DI-resolved queue. The application owns its lifecycle.
Monitoring-only queues can omit processor. They still report queue counts but cannot provide in-process processor measurements.
Async registration#
Use forRootAsync() when configuration comes from injected services. Put path and auth on the outer options: Nest constructs controller metadata before the async factory resolves.
This example assumes @nestjs/config is installed and your app provides AdminGuard:
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { QueuebertModule } from '@queuebert/nest';
import { AdminGuard } from './admin.guard';
@Module({
imports: [
QueuebertModule.forRootAsync({
path: 'admin/queue',
auth: { guards: [AdminGuard] },
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (injected: unknown) => {
const config = injected as ConfigService;
return {
queues: [{ name: config.getOrThrow<string>('EMAIL_QUEUE_NAME') }],
endpoints: ['metrics'],
};
},
}),
],
})
export class MonitoringModule {}The corresponding BullMQ queue must already be registered in the application. Imported auth/config providers must be visible to the modules that consume them.
Custom processors and caches#
Implement QueuebertProcessor.getProcessorStats() to supply your own statistics. QueuebertProcessorStats includes duration percentiles in milliseconds, job totals, rates expressed as fractions from 0 to 1, and a rolling throughput window. The base processor also allows custom statistics through getCustomStats().
Processors can expose managed caches through getCacheConfigs(): QueuebertCacheConfig[]. A cache entry identifies its id, label, keyPrefix, and compatible cache instance. Queuebert uses this metadata for cache statistics and the migration endpoints; arbitrary Redis keys are not automatically treated as managed caches.
Multiple Redis instances#
Use a named redis array and associate each queue with an ID. Supply a direct queue instance when monitoring the same name on another Redis deployment, and use a distinct statsKey. See migrations for a registration example and operational restrictions.