Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@nestjs/bull
Advanced tools
@nestjs/bull is a package for the NestJS framework that provides integration with Bull, a popular library for handling distributed job queues. It allows you to create, manage, and process jobs in a queue, making it useful for background processing, task scheduling, and more.
Creating a Queue
This code demonstrates how to set up a queue named 'my-queue' using the @nestjs/bull package. It configures the connection to a Redis server and registers the queue within a NestJS module.
```typescript
import { BullModule } from '@nestjs/bull';
@Module({
imports: [
BullModule.forRoot({
redis: {
host: 'localhost',
port: 6379,
},
}),
BullModule.registerQueue({
name: 'my-queue',
}),
],
})
export class AppModule {}
```
Adding Jobs to a Queue
This code shows how to add jobs to a queue. The `MyService` class injects the 'my-queue' queue and uses the `addJob` method to add a job with the provided data.
```typescript
import { InjectQueue } from '@nestjs/bull';
import { Queue } from 'bull';
import { Injectable } from '@nestjs/common';
@Injectable()
export class MyService {
constructor(@InjectQueue('my-queue') private readonly myQueue: Queue) {}
async addJob(data: any) {
await this.myQueue.add(data);
}
}
```
Processing Jobs
This code demonstrates how to process jobs in a queue. The `MyQueueProcessor` class is decorated with `@Processor('my-queue')` to indicate it will handle jobs from 'my-queue'. The `handleJob` method processes each job.
```typescript
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';
@Processor('my-queue')
export class MyQueueProcessor {
@Process()
async handleJob(job: Job) {
console.log('Processing job:', job.data);
// Add your job processing logic here
}
}
```
Bull is a Node.js library for creating and managing job queues. It is the underlying library used by @nestjs/bull. While @nestjs/bull provides integration with the NestJS framework, Bull can be used independently in any Node.js application.
Agenda is a lightweight job scheduling library for Node.js. It provides similar functionality to Bull but focuses more on job scheduling and recurring tasks. It uses MongoDB as its storage backend, whereas Bull uses Redis.
Kue is another job queue library for Node.js that uses Redis. It provides a simple API for creating and processing jobs, along with a built-in UI for monitoring job status. Kue is less actively maintained compared to Bull.
A progressive Node.js framework for building efficient and scalable server-side applications.
$ npm i --save @nestjs/bull bull
$ npm i --save-dev @types/bull
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
FAQs
Nest - modern, fast, powerful node.js web framework (@bull)
The npm package @nestjs/bull receives a total of 0 weekly downloads. As such, @nestjs/bull popularity was classified as not popular.
We found that @nestjs/bull demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.