Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@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 255,388 weekly downloads. As such, @nestjs/bull popularity was classified as 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.