@xnestjs/rabbitmq 1.11.2 → 1.12.0
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
|
@@ -72,21 +72,22 @@ configuration. By default, variables are prefixed with `RMQ_`.
|
|
|
72
72
|
|
|
73
73
|
<!--- BEGIN env --->
|
|
74
74
|
|
|
75
|
-
| Environment Variable | Type | Default
|
|
76
|
-
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
75
|
+
| Environment Variable | Type | Default | Description |
|
|
76
|
+
|--------------------------|-----------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
77
|
+
| `RMQ_HOSTS` | String[]! | `localhost:5672` | A list of RabbitMQ server hosts (hostname:port) to connect to. eg |
|
|
78
|
+
| `RMQ_VHOST` | String | | VHost |
|
|
79
|
+
| `RMQ_USERNAME` | String | | Username used for authenticating against the server |
|
|
80
|
+
| `RMQ_PASSWORD` | String | | Password used for authenticating against the server |
|
|
81
|
+
| `RMQ_ACQUIRE_TIMEOUT` | Number | `20000` | Milliseconds to wait before aborting a Channel creation attempt. |
|
|
82
|
+
| `RMQ_CONNECTION_NAME` | String | | Custom name for the connection, visible in the server's management UI |
|
|
83
|
+
| `RMQ_CONNECTION_TIMEOUT` | Number | `10000` | Max wait time, in milliseconds, for a connection attempt |
|
|
84
|
+
| `RMQ_FRAME_MAX` | Number | `8192` | Max size, in bytes, of AMQP data frames. Protocol max is 2^32-1. Actual value is negotiated with the server. |
|
|
85
|
+
| `RMQ_HEARTBEAT_INTERVAL` | Number | `60` | Period of time, in seconds, after which the TCP connection should be considered unreachable. Server may have its own max value, in which case the lowest of the two is used. A value of 0 will disable this feature. Heartbeats are sent every heartbeat / 2 seconds, so two missed heartbeats means the connection is dead. |
|
|
86
|
+
| `RMQ_MAX_CHANNELS` | Number | `2047` | Maximum active AMQP channels. 65535 is the protocol max. The server may also have a max value, in which case the lowest of the two is used. |
|
|
87
|
+
| `RMQ_RETRY_HIGH` | Number | `30000` | Max delay, in milliseconds, for exponential-backoff when reconnecting |
|
|
88
|
+
| `RMQ_RETRY_LOW` | Number | `1000` | Step size, in milliseconds, for exponential-backoff when reconnecting |
|
|
89
|
+
| `RMQ_NO_DELAY` | Boolean | `false` | Disable Nagle's algorithm for reduced latency. Disabling Nagle’s algorithm will enable the application to have many small packets in flight on the network at once, instead of a smaller number of large packets, which may increase load on the network, and may or may not benefit the application performance. |
|
|
90
|
+
| `RMQ_LAZY_CONNECT` | Boolean | `false` | If true, defers connecting to RabbitMQ until a message is |
|
|
90
91
|
|
|
91
92
|
<!--- END env --->
|
|
92
93
|
|
|
@@ -5,18 +5,17 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
6
6
|
const objects_1 = require("@jsopen/objects");
|
|
7
7
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
|
-
function getRabbitmqConfig(
|
|
8
|
+
function getRabbitmqConfig(init, prefix = 'RMQ_') {
|
|
9
9
|
const env = node_process_1.default.env;
|
|
10
10
|
const options = {};
|
|
11
|
-
if (Array.isArray(
|
|
12
|
-
options.
|
|
13
|
-
else if (typeof
|
|
14
|
-
(0, objects_1.merge)(options,
|
|
11
|
+
if (Array.isArray(init))
|
|
12
|
+
options.hosts = init;
|
|
13
|
+
else if (typeof init === 'object') {
|
|
14
|
+
(0, objects_1.merge)(options, init, { deep: true });
|
|
15
15
|
}
|
|
16
16
|
else
|
|
17
|
-
options.
|
|
18
|
-
|
|
19
|
-
'amqp://localhost:5672').split(/\s*,\s*/) || ['amqp://guest:guest@localhost:5672'];
|
|
17
|
+
options.hosts = (init || env[prefix + 'HOSTS'] || 'localhost:5672').split(/\s*,\s*/) || ['localhost:5672'];
|
|
18
|
+
options.vhost = options.vhost ?? env[prefix + 'VHOST'];
|
|
20
19
|
options.username = options.username ?? env[prefix + 'USERNAME'];
|
|
21
20
|
options.password = options.password ?? env[prefix + 'PASSWORD'];
|
|
22
21
|
options.acquireTimeout =
|
|
@@ -104,9 +104,9 @@ let RabbitmqCoreModule = RabbitmqCoreModule_1 = class RabbitmqCoreModule {
|
|
|
104
104
|
}
|
|
105
105
|
async onApplicationBootstrap() {
|
|
106
106
|
const options = this.connectionOptions;
|
|
107
|
-
if (options.lazyConnect || !options.
|
|
107
|
+
if (options.lazyConnect || !options.hosts?.length)
|
|
108
108
|
return;
|
|
109
|
-
this.logger?.log('Connecting to RabbitMQ at ' + ansi_colors_1.default.blue(options.
|
|
109
|
+
this.logger?.log('Connecting to RabbitMQ at ' + ansi_colors_1.default.blue(options.hosts.toString()));
|
|
110
110
|
common_1.Logger.flush();
|
|
111
111
|
await this.client.onConnect();
|
|
112
112
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { merge, omitNullish } from '@jsopen/objects';
|
|
3
3
|
import { toBoolean, toInt } from 'putil-varhelpers';
|
|
4
|
-
export function getRabbitmqConfig(
|
|
4
|
+
export function getRabbitmqConfig(init, prefix = 'RMQ_') {
|
|
5
5
|
const env = process.env;
|
|
6
6
|
const options = {};
|
|
7
|
-
if (Array.isArray(
|
|
8
|
-
options.
|
|
9
|
-
else if (typeof
|
|
10
|
-
merge(options,
|
|
7
|
+
if (Array.isArray(init))
|
|
8
|
+
options.hosts = init;
|
|
9
|
+
else if (typeof init === 'object') {
|
|
10
|
+
merge(options, init, { deep: true });
|
|
11
11
|
}
|
|
12
12
|
else
|
|
13
|
-
options.
|
|
14
|
-
|
|
15
|
-
'amqp://localhost:5672').split(/\s*,\s*/) || ['amqp://guest:guest@localhost:5672'];
|
|
13
|
+
options.hosts = (init || env[prefix + 'HOSTS'] || 'localhost:5672').split(/\s*,\s*/) || ['localhost:5672'];
|
|
14
|
+
options.vhost = options.vhost ?? env[prefix + 'VHOST'];
|
|
16
15
|
options.username = options.username ?? env[prefix + 'USERNAME'];
|
|
17
16
|
options.password = options.password ?? env[prefix + 'PASSWORD'];
|
|
18
17
|
options.acquireTimeout =
|
|
@@ -101,9 +101,9 @@ let RabbitmqCoreModule = RabbitmqCoreModule_1 = class RabbitmqCoreModule {
|
|
|
101
101
|
}
|
|
102
102
|
async onApplicationBootstrap() {
|
|
103
103
|
const options = this.connectionOptions;
|
|
104
|
-
if (options.lazyConnect || !options.
|
|
104
|
+
if (options.lazyConnect || !options.hosts?.length)
|
|
105
105
|
return;
|
|
106
|
-
this.logger?.log('Connecting to RabbitMQ at ' + colors.blue(options.
|
|
106
|
+
this.logger?.log('Connecting to RabbitMQ at ' + colors.blue(options.hosts.toString()));
|
|
107
107
|
Logger.flush();
|
|
108
108
|
await this.client.onConnect();
|
|
109
109
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xnestjs/rabbitmq",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "NestJS extension library for RabbitMQ",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@jsopen/objects": "^1.
|
|
8
|
+
"@jsopen/objects": "^1.6.0",
|
|
9
9
|
"ansi-colors": "^4.1.3",
|
|
10
10
|
"putil-varhelpers": "^1.6.5",
|
|
11
11
|
"tslib": "^2.8.1"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RabbitmqConnectionOptions } from './types';
|
|
2
|
-
export declare function getRabbitmqConfig(
|
|
2
|
+
export declare function getRabbitmqConfig(init: string | string[] | Partial<RabbitmqConnectionOptions>, prefix?: string): RabbitmqConnectionOptions;
|
package/types/types.d.ts
CHANGED
|
@@ -4,8 +4,7 @@ import type { InjectionToken } from '@nestjs/common/interfaces/modules/injection
|
|
|
4
4
|
import * as rabbit from 'rabbitmq-client';
|
|
5
5
|
export type RmqClient = rabbit.Connection;
|
|
6
6
|
export declare const RmqClient: typeof rabbit.Connection;
|
|
7
|
-
export interface RabbitmqConnectionOptions extends Pick<rabbit.ConnectionOptions, 'username' | 'password' | 'acquireTimeout' | 'connectionName' | 'connectionTimeout' | 'frameMax' | 'heartbeat' | 'maxChannels' | 'retryHigh' | 'retryLow' | 'noDelay' | 'tls' | 'socket'> {
|
|
8
|
-
urls?: string[];
|
|
7
|
+
export interface RabbitmqConnectionOptions extends Pick<rabbit.ConnectionOptions, 'hosts' | 'vhost' | 'username' | 'password' | 'acquireTimeout' | 'connectionName' | 'connectionTimeout' | 'frameMax' | 'heartbeat' | 'maxChannels' | 'retryHigh' | 'retryLow' | 'noDelay' | 'tls' | 'socket'> {
|
|
9
8
|
lazyConnect?: boolean;
|
|
10
9
|
}
|
|
11
10
|
export interface RabbitmqModuleOptions extends BaseModuleOptions {
|