@xnestjs/rabbitmq 1.7.1 → 1.8.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 CHANGED
@@ -28,16 +28,15 @@ import { Module } from '@nestjs/common';
28
28
  import { RabbitmqModule } from '@xnestjs/rabbitmq';
29
29
 
30
30
  @Module({
31
- imports: [
32
- RabbitmqModule.forRoot({
33
- useValue: {
34
- urls: ['amqp://localhost:5672'],
35
- },
36
- }),
37
- ],
31
+ imports: [
32
+ RabbitmqModule.forRoot({
33
+ useValue: {
34
+ urls: ['amqp://localhost:5672'],
35
+ },
36
+ }),
37
+ ],
38
38
  })
39
- export class MyModule {
40
- }
39
+ export class MyModule {}
41
40
  ```
42
41
 
43
42
  ### Asynchronous Registration
@@ -51,18 +50,17 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
51
50
  import { RabbitmqModule } from '@xnestjs/rabbitmq';
52
51
 
53
52
  @Module({
54
- imports: [
55
- ConfigModule.forRoot(),
56
- RabbitmqModule.forRootAsync({
57
- inject: [ConfigService],
58
- useFactory: (config: ConfigService) => ({
59
- urls: config.get<string[]>('RMQ_URLS'),
60
- }),
61
- }),
62
- ],
53
+ imports: [
54
+ ConfigModule.forRoot(),
55
+ RabbitmqModule.forRootAsync({
56
+ inject: [ConfigService],
57
+ useFactory: (config: ConfigService) => ({
58
+ urls: config.get<string[]>('RMQ_URLS'),
59
+ }),
60
+ }),
61
+ ],
63
62
  })
64
- export class MyModule {
65
- }
63
+ export class MyModule {}
66
64
  ```
67
65
 
68
66
  ## ⚙️ Environment Variables
@@ -70,18 +68,18 @@ export class MyModule {
70
68
  The module supports configuration via environment variables. These can be used in place of or alongside the object-based
71
69
  configuration. By default, variables are prefixed with `RMQ_`.
72
70
 
73
- <--- BEGIN env --->
71
+ <!--- BEGIN env --->
74
72
 
75
73
  | 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. |
83
-
84
- <--- END env --->
74
+ | ----------------------------- | --------- | ------- | ------------------------------------------------------------------------ |
75
+ | `RMQ_URLS` | String[]! | | A list of RabbitMQ server URLs to connect to. |
76
+ | `RMQ_PREFETCH_COUNT` | Number | | Sets the prefetch count for consumers to control message flow. |
77
+ | `RMQ_MAX_CONNECTION_ATTEMPTS` | Number | | Maximum number of retry attempts to establish a connection. |
78
+ | `RMQ_RECONNECT_TIME` | Number | | Time (in milliseconds) to wait before trying to reconnect. |
79
+ | `RMQ_HEARTBEAT_INTERVAL` | Number | | Interval (in seconds) for the RabbitMQ heartbeat mechanism. |
80
+ | `RMQ_LAZY_CONNECT` | Boolean | `false` | If true, defers connecting to RabbitMQ until a message is sent/received. |
81
+
82
+ <!--- END env --->
85
83
 
86
84
  > 💡 You can customize the environment variable prefix during module registration by passing the `envPrefix` option.
87
85
 
@@ -8,14 +8,22 @@ const putil_varhelpers_1 = require("putil-varhelpers");
8
8
  function getRabbitmqConfig(moduleOptions, prefix = 'RMQ_') {
9
9
  const options = (0, objects_1.clone)(moduleOptions);
10
10
  const env = node_process_1.default.env;
11
- options.urls = options.urls || (env[prefix + 'URLS'] ?? 'amqp://localhost:5672').split(/\s*,\s*/);
12
- options.prefetchCount = options.prefetchCount ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PREFETCH_COUNT']);
13
- options.maxConnectionAttempts = options.maxConnectionAttempts ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CONNECTION_ATTEMPTS']);
11
+ options.urls =
12
+ options.urls ||
13
+ (env[prefix + 'URLS'] ?? 'amqp://localhost:5672').split(/\s*,\s*/);
14
+ options.prefetchCount =
15
+ options.prefetchCount ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PREFETCH_COUNT']);
16
+ options.maxConnectionAttempts =
17
+ options.maxConnectionAttempts ??
18
+ (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CONNECTION_ATTEMPTS']);
14
19
  options.socketOptions = options.socketOptions ?? {};
15
20
  options.socketOptions.reconnectTimeInSeconds =
16
- options.socketOptions.reconnectTimeInSeconds ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'RECONNECT_TIME']);
21
+ options.socketOptions.reconnectTimeInSeconds ??
22
+ (0, putil_varhelpers_1.toInt)(env[prefix + 'RECONNECT_TIME']);
17
23
  options.socketOptions.heartbeatIntervalInSeconds =
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');
24
+ options.socketOptions.heartbeatIntervalInSeconds ??
25
+ (0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_INTERVAL']);
26
+ options.lazyConnect =
27
+ options.lazyConnect ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LAZY_CONNECT'] ?? 'false');
20
28
  return options;
21
29
  }
@@ -108,6 +108,9 @@ let RabbitmqCoreModule = RabbitmqCoreModule_1 = class RabbitmqCoreModule {
108
108
  }
109
109
  async onApplicationBootstrap() {
110
110
  const options = this.connectionOptions;
111
+ this.client.on('error', e => {
112
+ console.log(e);
113
+ });
111
114
  if (options.lazyConnect || !options.urls?.length)
112
115
  return;
113
116
  this.logger?.log('Connecting to RabbitMQ at ' + ansi_colors_1.default.blue(options.urls.join(',')));
@@ -4,14 +4,22 @@ 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;
7
- options.urls = options.urls || (env[prefix + 'URLS'] ?? 'amqp://localhost:5672').split(/\s*,\s*/);
8
- options.prefetchCount = options.prefetchCount ?? toInt(env[prefix + 'PREFETCH_COUNT']);
9
- options.maxConnectionAttempts = options.maxConnectionAttempts ?? toInt(env[prefix + 'MAX_CONNECTION_ATTEMPTS']);
7
+ options.urls =
8
+ options.urls ||
9
+ (env[prefix + 'URLS'] ?? 'amqp://localhost:5672').split(/\s*,\s*/);
10
+ options.prefetchCount =
11
+ options.prefetchCount ?? toInt(env[prefix + 'PREFETCH_COUNT']);
12
+ options.maxConnectionAttempts =
13
+ options.maxConnectionAttempts ??
14
+ toInt(env[prefix + 'MAX_CONNECTION_ATTEMPTS']);
10
15
  options.socketOptions = options.socketOptions ?? {};
11
16
  options.socketOptions.reconnectTimeInSeconds =
12
- options.socketOptions.reconnectTimeInSeconds ?? toInt(env[prefix + 'RECONNECT_TIME']);
17
+ options.socketOptions.reconnectTimeInSeconds ??
18
+ toInt(env[prefix + 'RECONNECT_TIME']);
13
19
  options.socketOptions.heartbeatIntervalInSeconds =
14
- options.socketOptions.heartbeatIntervalInSeconds ?? toInt(env[prefix + 'HEARTBEAT_INTERVAL']);
15
- options.lazyConnect = toBoolean(env[prefix + 'LAZY_CONNECT'] ?? 'false');
20
+ options.socketOptions.heartbeatIntervalInSeconds ??
21
+ toInt(env[prefix + 'HEARTBEAT_INTERVAL']);
22
+ options.lazyConnect =
23
+ options.lazyConnect ?? toBoolean(env[prefix + 'LAZY_CONNECT'] ?? 'false');
16
24
  return options;
17
25
  }
@@ -2,8 +2,8 @@ var RabbitmqCoreModule_1;
2
2
  import { __decorate, __metadata, __param } from "tslib";
3
3
  import assert from 'node:assert';
4
4
  import * as crypto from 'node:crypto';
5
- import { Inject, Logger } from '@nestjs/common';
6
- import { ClientRMQ, ClientsModule, Transport } from '@nestjs/microservices';
5
+ import { Inject, Logger, } from '@nestjs/common';
6
+ import { ClientRMQ, ClientsModule, Transport, } from '@nestjs/microservices';
7
7
  import colors from 'ansi-colors';
8
8
  import { RMQ_CONNECTION_OPTIONS, RMQ_MODULE_ID } from './constants.js';
9
9
  import { getRabbitmqConfig } from './get-rabbitmq-config.js';
@@ -105,6 +105,9 @@ let RabbitmqCoreModule = RabbitmqCoreModule_1 = class RabbitmqCoreModule {
105
105
  }
106
106
  async onApplicationBootstrap() {
107
107
  const options = this.connectionOptions;
108
+ this.client.on('error', e => {
109
+ console.log(e);
110
+ });
108
111
  if (options.lazyConnect || !options.urls?.length)
109
112
  return;
110
113
  this.logger?.log('Connecting to RabbitMQ at ' + colors.blue(options.urls.join(',')));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnestjs/rabbitmq",
3
- "version": "1.7.1",
3
+ "version": "1.8.1",
4
4
  "description": "NestJS extension library for RabbitMQ",
5
5
  "author": "Panates",
6
6
  "license": "MIT",