@kasifraza/nestjs-queue-helper
v1.0.1
Published
Unified queue abstraction for RabbitMQ/Kafka/SQS with retry and DLQ patterns
Maintainers
Readme
@kasifraza/nestjs-queue-helper
Unified queue abstraction for NestJS supporting RabbitMQ, Kafka, SQS, and in-memory providers with retry and DLQ patterns.
Install
npm install @kasifraza/nestjs-queue-helperSetup
import { QueueModule } from '@kasifraza/nestjs-queue-helper';
@Module({
imports: [
QueueModule.register({
provider: 'memory', // 'rabbitmq' | 'kafka' | 'sqs' | 'memory'
connection: {},
retries: { maxRetries: 3, backoff: 100, dlq: 'dead-letter-queue' },
}),
],
})
export class AppModule {}Usage
Emit events
import { QueueService } from '@kasifraza/nestjs-queue-helper';
@Injectable()
export class OrderService {
constructor(private queue: QueueService) {}
async createOrder(dto: CreateOrderDto) {
const order = await this.repo.save(dto);
await this.queue.emit('order.created', { orderId: order.id });
return order;
}
}Consume events
import { QueueConsumer } from '@kasifraza/nestjs-queue-helper';
@Injectable()
export class NotificationHandler {
@QueueConsumer('order.created')
async handleOrderCreated(payload: { orderId: string }) {
// send notification
}
}Batch emit
await this.queue.emitBatch('user.updated', [
{ userId: '1', name: 'John' },
{ userId: '2', name: 'Jane' },
]);Features
- Multi-provider — RabbitMQ, Kafka, SQS, or in-memory for testing
- Retry with backoff — automatic retries on failure
- Dead Letter Queue — failed messages routed to DLQ after max retries
- Decorators —
@QueueConsumerfor clean handler registration - Batch support — emit multiple messages at once
- InMemoryProvider — perfect for unit tests
API
| Export | Description |
|--------|-------------|
| QueueModule.register(options) | Configure queue provider |
| QueueService | emit(event, payload), emitBatch(event, payloads[]) |
| @QueueConsumer(event, options?) | Decorator for event handlers |
| InMemoryProvider | Built-in provider for testing |
| QueueProvider | Interface to implement custom providers |
License
MIT
