@xnestjs/rabbitmq 1.7.0 → 1.7.1
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 +38 -23
- package/cjs/get-rabbitmq-config.js +1 -0
- package/esm/get-rabbitmq-config.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
# @xnestjs/rabbitmq
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**@xnestjs/rabbitmq** is a powerful extension library for integrating RabbitMQ into your NestJS applications with ease.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 📦 Installation
|
|
6
|
+
|
|
7
|
+
Use npm:
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
10
|
npm install @xnestjs/rabbitmq
|
|
9
|
-
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or with yarn:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
10
16
|
yarn add @xnestjs/rabbitmq
|
|
11
17
|
```
|
|
12
18
|
|
|
13
|
-
##
|
|
19
|
+
## 🚀 Getting Started
|
|
14
20
|
|
|
15
|
-
###
|
|
21
|
+
### Synchronous Registration
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
Here's how to register the RabbitMQ module synchronously in your NestJS application:
|
|
18
24
|
|
|
19
25
|
```ts
|
|
20
|
-
// module.ts
|
|
26
|
+
// my.module.ts
|
|
21
27
|
import { Module } from '@nestjs/common';
|
|
22
28
|
import { RabbitmqModule } from '@xnestjs/rabbitmq';
|
|
23
29
|
|
|
@@ -34,42 +40,51 @@ export class MyModule {
|
|
|
34
40
|
}
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
###
|
|
43
|
+
### Asynchronous Registration
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
For dynamic configuration (e.g., using a ConfigService), use the async registration method:
|
|
40
46
|
|
|
41
47
|
```ts
|
|
42
|
-
// module.ts
|
|
48
|
+
// my.module.ts
|
|
43
49
|
import { Module } from '@nestjs/common';
|
|
50
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
44
51
|
import { RabbitmqModule } from '@xnestjs/rabbitmq';
|
|
45
52
|
|
|
46
53
|
@Module({
|
|
47
54
|
imports: [
|
|
55
|
+
ConfigModule.forRoot(),
|
|
48
56
|
RabbitmqModule.forRootAsync({
|
|
49
|
-
inject: [
|
|
57
|
+
inject: [ConfigService],
|
|
50
58
|
useFactory: (config: ConfigService) => ({
|
|
51
|
-
urls: config.get('RMQ_URLS'),
|
|
59
|
+
urls: config.get<string[]>('RMQ_URLS'),
|
|
52
60
|
}),
|
|
53
61
|
}),
|
|
54
|
-
]
|
|
62
|
+
],
|
|
55
63
|
})
|
|
56
64
|
export class MyModule {
|
|
57
65
|
}
|
|
58
66
|
```
|
|
59
67
|
|
|
60
|
-
## Environment Variables
|
|
68
|
+
## ⚙️ Environment Variables
|
|
61
69
|
|
|
62
|
-
The
|
|
63
|
-
|
|
70
|
+
The module supports configuration via environment variables. These can be used in place of or alongside the object-based
|
|
71
|
+
configuration. By default, variables are prefixed with `RMQ_`.
|
|
64
72
|
|
|
65
73
|
<--- BEGIN env --->
|
|
66
74
|
|
|
67
|
-
| Environment Variable
|
|
68
|
-
|
|
69
|
-
| RMQ_URLS | String[]! |
|
|
70
|
-
| RMQ_PREFETCH_COUNT | Number |
|
|
71
|
-
| RMQ_MAX_CONNECTION_ATTEMPTS | Number |
|
|
72
|
-
| RMQ_RECONNECT_TIME | Number |
|
|
73
|
-
| RMQ_HEARTBEAT_INTERVAL | Number |
|
|
75
|
+
| Environment Variable | Type | Default | Description |
|
|
76
|
+
|-------------------------------|-----------|---------|--------------------------------------------------------------------------|
|
|
77
|
+
| `RMQ_URLS` | String[]! | — | A list of RabbitMQ server URLs to connect to. |
|
|
78
|
+
| `RMQ_PREFETCH_COUNT` | Number | — | Sets the prefetch count for consumers to control message flow. |
|
|
79
|
+
| `RMQ_MAX_CONNECTION_ATTEMPTS` | Number | — | Maximum number of retry attempts to establish a connection. |
|
|
80
|
+
| `RMQ_RECONNECT_TIME` | Number | — | Time (in milliseconds) to wait before trying to reconnect. |
|
|
81
|
+
| `RMQ_HEARTBEAT_INTERVAL` | Number | — | Interval (in seconds) for the RabbitMQ heartbeat mechanism. |
|
|
82
|
+
| `RMQ_LAZY_CONNECT` | Boolean | false | If true, defers connecting to RabbitMQ until a message is sent/received. |
|
|
74
83
|
|
|
75
84
|
<--- END env --->
|
|
85
|
+
|
|
86
|
+
> 💡 You can customize the environment variable prefix during module registration by passing the `envPrefix` option.
|
|
87
|
+
|
|
88
|
+
## 📚 License
|
|
89
|
+
|
|
90
|
+
MIT License
|
|
@@ -16,5 +16,6 @@ function getRabbitmqConfig(moduleOptions, prefix = 'RMQ_') {
|
|
|
16
16
|
options.socketOptions.reconnectTimeInSeconds ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'RECONNECT_TIME']);
|
|
17
17
|
options.socketOptions.heartbeatIntervalInSeconds =
|
|
18
18
|
options.socketOptions.heartbeatIntervalInSeconds ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_INTERVAL']);
|
|
19
|
+
options.lazyConnect = (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LAZY_CONNECT'] ?? 'false');
|
|
19
20
|
return options;
|
|
20
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { clone } from '@jsopen/objects';
|
|
3
|
-
import { toInt } from 'putil-varhelpers';
|
|
3
|
+
import { toBoolean, toInt } from 'putil-varhelpers';
|
|
4
4
|
export function getRabbitmqConfig(moduleOptions, prefix = 'RMQ_') {
|
|
5
5
|
const options = clone(moduleOptions);
|
|
6
6
|
const env = process.env;
|
|
@@ -12,5 +12,6 @@ export function getRabbitmqConfig(moduleOptions, prefix = 'RMQ_') {
|
|
|
12
12
|
options.socketOptions.reconnectTimeInSeconds ?? toInt(env[prefix + 'RECONNECT_TIME']);
|
|
13
13
|
options.socketOptions.heartbeatIntervalInSeconds =
|
|
14
14
|
options.socketOptions.heartbeatIntervalInSeconds ?? toInt(env[prefix + 'HEARTBEAT_INTERVAL']);
|
|
15
|
+
options.lazyConnect = toBoolean(env[prefix + 'LAZY_CONNECT'] ?? 'false');
|
|
15
16
|
return options;
|
|
16
17
|
}
|