nestjs-power-queues 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,144 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# nestjs-power-queues — Secure, Scalable & Production‑Ready power-queues Integration for NestJS
|
|
2
|
+
|
|
3
|
+
This module is a **dedicated, production-ready NestJS wrapper around `power-queues`** — a high‑performance Redis abstraction layer for Node.js.
|
|
4
|
+
|
|
5
|
+
It is a **structured, type-safe, and feature-rich integration** designed specifically to bring all the power of `power-queues` into the NestJS ecosystem with zero friction.
|
|
6
|
+
|
|
7
|
+
# 📦 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install nestjs-power-queues
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
# 🧪 Quick Start Example
|
|
14
|
+
|
|
15
|
+
## For example, you need to specify 2 connections: `queues1` and `queues2`
|
|
16
|
+
|
|
17
|
+
### 1. 🔐 Environment Variables (power-redis -Friendly)
|
|
18
|
+
|
|
19
|
+
Everything is configured using environment variables:
|
|
20
|
+
|
|
21
|
+
```env
|
|
22
|
+
REDIS_<NAME>_HOST=127.0.0.1
|
|
23
|
+
REDIS_<NAME>_PORT=6379
|
|
24
|
+
REDIS_<NAME>_PASSWORD=pass
|
|
25
|
+
REDIS_<NAME>_DATABASE=0
|
|
26
|
+
|
|
27
|
+
# TLS
|
|
28
|
+
REDIS_<NAME>_TLS_CRT=/etc/ssl/client.crt
|
|
29
|
+
REDIS_<NAME>_TLS_KEY=/etc/ssl/client.key
|
|
30
|
+
REDIS_<NAME>_TLS_CA_CRT=/etc/ssl/ca.crt
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Instead of `<NAME>` you need to specify a custom connection name and then specify these names in `QueueModule.forRoot` (allowed in lowercase).
|
|
34
|
+
For example:
|
|
35
|
+
|
|
36
|
+
```env
|
|
37
|
+
REDIS_QUEUES1_HOST=127.0.0.1
|
|
38
|
+
REDIS_QUEUES1_PORT=6379
|
|
39
|
+
REDIS_QUEUES1_PASSWORD=
|
|
40
|
+
REDIS_QUEUES1_DATABASE=0
|
|
41
|
+
|
|
42
|
+
REDIS_QUEUES2_HOST=127.0.0.1
|
|
43
|
+
REDIS_QUEUES2_PORT=6379
|
|
44
|
+
REDIS_QUEUES2_PASSWORD=
|
|
45
|
+
REDIS_QUEUES2_DATABASE=0
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
TLS fields are optional.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### 2. Register module with multiple Redis clients
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { QueueModule } from 'nestjs-power-queues';
|
|
56
|
+
|
|
57
|
+
@Module({
|
|
58
|
+
imports: [
|
|
59
|
+
QueueModule.forRoot([ 'queues1', 'queues2' ]),
|
|
60
|
+
],
|
|
61
|
+
})
|
|
62
|
+
export class AppModule {}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### 3. Inject in a service
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { Injectable } from '@nestjs/common';
|
|
71
|
+
import {
|
|
72
|
+
InjectQueue,
|
|
73
|
+
QueueService,
|
|
74
|
+
} from 'nestjs-power-queues';
|
|
75
|
+
|
|
76
|
+
@Injectable()
|
|
77
|
+
export class MyService {
|
|
78
|
+
constructor(
|
|
79
|
+
@InjectQueue('queues1') private readonly queueService1: QueueService,
|
|
80
|
+
@InjectQueue('queues2') private readonly queueService2: QueueService,
|
|
81
|
+
) {}
|
|
82
|
+
|
|
83
|
+
async test() {
|
|
84
|
+
await this.queueService1.addTasks('example:jobs', [
|
|
85
|
+
{ payload },
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. Create job processor
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { Injectable } from '@nestjs/common';
|
|
95
|
+
import {
|
|
96
|
+
InjectRedis,
|
|
97
|
+
RedisService,
|
|
98
|
+
} from 'nestjs-power-redis';
|
|
99
|
+
import { QueueService } from 'nestjs-power-queues';
|
|
100
|
+
|
|
101
|
+
@Injectable()
|
|
102
|
+
export class MyService extends QueueService {
|
|
103
|
+
public readonly stream: string = `example:jobs`;
|
|
104
|
+
public readonly workerBatchTasksCount: number = 8192;
|
|
105
|
+
public readonly runOnInit: boolean = true;
|
|
106
|
+
public readonly executeBatchAtOnce: boolean = true;
|
|
107
|
+
|
|
108
|
+
constructor(
|
|
109
|
+
@InjectRedis('queues1') public readonly redisService: RedisService,
|
|
110
|
+
) {}
|
|
111
|
+
|
|
112
|
+
async onExecute(id, payload) {
|
|
113
|
+
// business-logic
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The `runOnInit` parameter determines whether queue processing should start immediately after the application starts.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 🏗️ How It Works Internally
|
|
123
|
+
|
|
124
|
+
### queueRoot()
|
|
125
|
+
Loads all Redis configurations based on environment variables, applies TLS if present, and sets reconnection strategies.
|
|
126
|
+
|
|
127
|
+
### RedisModule.forRoot()
|
|
128
|
+
Creates dynamic providers for each Redis connection:
|
|
129
|
+
```
|
|
130
|
+
RedisQueue_queues1
|
|
131
|
+
RedisQueue_queues2
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
These providers are available through:
|
|
135
|
+
```ts
|
|
136
|
+
@InjectQueue('queues1')
|
|
137
|
+
@InjectQueue('queues2')
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 📜 License
|
|
143
|
+
|
|
144
|
+
MIT - free for commercial and private use.
|