@nathapp/nestjs-microservices 1.0.0-rc.10 → 1.0.0-rc.11
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/dist/adapter/adapter.interface.d.ts +178 -0
- package/dist/adapter/adapter.interface.js +2 -0
- package/dist/adapter/http-service.adapter.d.ts +5 -1
- package/dist/adapter/http-service.adapter.js +8 -0
- package/dist/adapter/index.d.ts +3 -1
- package/dist/adapter/index.js +3 -1
- package/dist/adapter/micro-service-adapter-factory.d.ts +3 -2
- package/dist/adapter/micro-service-adapter-factory.js +32 -0
- package/dist/adapter/micro-service.adapter.d.ts +11 -7
- package/dist/adapter/nestjs-micro-service.adapter.d.ts +11 -0
- package/dist/adapter/nestjs-micro-service.adapter.js +21 -0
- package/dist/client/custom-client-rmq.d.ts +42 -0
- package/dist/client/custom-client-rmq.js +197 -0
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +3 -1
- package/dist/client/service-client.d.ts +5 -3
- package/dist/client/service-client.js +1 -0
- package/dist/enum/transport.enum.d.ts +8 -1
- package/dist/enum/transport.enum.js +8 -1
- package/dist/external/grpc-options.interface.d.ts +16 -0
- package/dist/external/grpc-options.interface.js +2 -0
- package/dist/external/kafka.interface.d.ts +1118 -0
- package/dist/external/kafka.interface.js +77 -0
- package/dist/external/mqtt-client.interface.d.ts +32 -0
- package/dist/external/mqtt-client.interface.js +3 -0
- package/dist/external/mqtt-options.interface.d.ts +55 -0
- package/dist/external/mqtt-options.interface.js +2 -0
- package/dist/external/redis.interface.d.ts +53 -0
- package/dist/external/redis.interface.js +2 -0
- package/dist/external/rmq-url.interface.d.ts +28 -0
- package/dist/external/rmq-url.interface.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server/custom-server-rmq.d.ts +27 -0
- package/dist/server/custom-server-rmq.js +159 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +7 -0
- package/dist/server/server-keepalive.d.ts +7 -0
- package/dist/server/server-keepalive.js +21 -0
- package/lib/external/README.md +1 -0
- package/package.json +37 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompressionCodecs = exports.CompressionTypes = exports.logLevel = exports.AssignerProtocol = exports.PartitionAssigners = exports.ResourcePatternTypes = exports.AclOperationTypes = exports.AclPermissionTypes = exports.ConfigSource = exports.ConfigResourceTypes = exports.AclResourceTypes = exports.Partitioners = void 0;
|
|
4
|
+
var AclResourceTypes;
|
|
5
|
+
(function (AclResourceTypes) {
|
|
6
|
+
AclResourceTypes[AclResourceTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
|
7
|
+
AclResourceTypes[AclResourceTypes["ANY"] = 1] = "ANY";
|
|
8
|
+
AclResourceTypes[AclResourceTypes["TOPIC"] = 2] = "TOPIC";
|
|
9
|
+
AclResourceTypes[AclResourceTypes["GROUP"] = 3] = "GROUP";
|
|
10
|
+
AclResourceTypes[AclResourceTypes["CLUSTER"] = 4] = "CLUSTER";
|
|
11
|
+
AclResourceTypes[AclResourceTypes["TRANSACTIONAL_ID"] = 5] = "TRANSACTIONAL_ID";
|
|
12
|
+
AclResourceTypes[AclResourceTypes["DELEGATION_TOKEN"] = 6] = "DELEGATION_TOKEN";
|
|
13
|
+
})(AclResourceTypes = exports.AclResourceTypes || (exports.AclResourceTypes = {}));
|
|
14
|
+
var ConfigResourceTypes;
|
|
15
|
+
(function (ConfigResourceTypes) {
|
|
16
|
+
ConfigResourceTypes[ConfigResourceTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
|
17
|
+
ConfigResourceTypes[ConfigResourceTypes["TOPIC"] = 2] = "TOPIC";
|
|
18
|
+
ConfigResourceTypes[ConfigResourceTypes["BROKER"] = 4] = "BROKER";
|
|
19
|
+
ConfigResourceTypes[ConfigResourceTypes["BROKER_LOGGER"] = 8] = "BROKER_LOGGER";
|
|
20
|
+
})(ConfigResourceTypes = exports.ConfigResourceTypes || (exports.ConfigResourceTypes = {}));
|
|
21
|
+
var ConfigSource;
|
|
22
|
+
(function (ConfigSource) {
|
|
23
|
+
ConfigSource[ConfigSource["UNKNOWN"] = 0] = "UNKNOWN";
|
|
24
|
+
ConfigSource[ConfigSource["TOPIC_CONFIG"] = 1] = "TOPIC_CONFIG";
|
|
25
|
+
ConfigSource[ConfigSource["DYNAMIC_BROKER_CONFIG"] = 2] = "DYNAMIC_BROKER_CONFIG";
|
|
26
|
+
ConfigSource[ConfigSource["DYNAMIC_DEFAULT_BROKER_CONFIG"] = 3] = "DYNAMIC_DEFAULT_BROKER_CONFIG";
|
|
27
|
+
ConfigSource[ConfigSource["STATIC_BROKER_CONFIG"] = 4] = "STATIC_BROKER_CONFIG";
|
|
28
|
+
ConfigSource[ConfigSource["DEFAULT_CONFIG"] = 5] = "DEFAULT_CONFIG";
|
|
29
|
+
ConfigSource[ConfigSource["DYNAMIC_BROKER_LOGGER_CONFIG"] = 6] = "DYNAMIC_BROKER_LOGGER_CONFIG";
|
|
30
|
+
})(ConfigSource = exports.ConfigSource || (exports.ConfigSource = {}));
|
|
31
|
+
var AclPermissionTypes;
|
|
32
|
+
(function (AclPermissionTypes) {
|
|
33
|
+
AclPermissionTypes[AclPermissionTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
|
34
|
+
AclPermissionTypes[AclPermissionTypes["ANY"] = 1] = "ANY";
|
|
35
|
+
AclPermissionTypes[AclPermissionTypes["DENY"] = 2] = "DENY";
|
|
36
|
+
AclPermissionTypes[AclPermissionTypes["ALLOW"] = 3] = "ALLOW";
|
|
37
|
+
})(AclPermissionTypes = exports.AclPermissionTypes || (exports.AclPermissionTypes = {}));
|
|
38
|
+
var AclOperationTypes;
|
|
39
|
+
(function (AclOperationTypes) {
|
|
40
|
+
AclOperationTypes[AclOperationTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
|
41
|
+
AclOperationTypes[AclOperationTypes["ANY"] = 1] = "ANY";
|
|
42
|
+
AclOperationTypes[AclOperationTypes["ALL"] = 2] = "ALL";
|
|
43
|
+
AclOperationTypes[AclOperationTypes["READ"] = 3] = "READ";
|
|
44
|
+
AclOperationTypes[AclOperationTypes["WRITE"] = 4] = "WRITE";
|
|
45
|
+
AclOperationTypes[AclOperationTypes["CREATE"] = 5] = "CREATE";
|
|
46
|
+
AclOperationTypes[AclOperationTypes["DELETE"] = 6] = "DELETE";
|
|
47
|
+
AclOperationTypes[AclOperationTypes["ALTER"] = 7] = "ALTER";
|
|
48
|
+
AclOperationTypes[AclOperationTypes["DESCRIBE"] = 8] = "DESCRIBE";
|
|
49
|
+
AclOperationTypes[AclOperationTypes["CLUSTER_ACTION"] = 9] = "CLUSTER_ACTION";
|
|
50
|
+
AclOperationTypes[AclOperationTypes["DESCRIBE_CONFIGS"] = 10] = "DESCRIBE_CONFIGS";
|
|
51
|
+
AclOperationTypes[AclOperationTypes["ALTER_CONFIGS"] = 11] = "ALTER_CONFIGS";
|
|
52
|
+
AclOperationTypes[AclOperationTypes["IDEMPOTENT_WRITE"] = 12] = "IDEMPOTENT_WRITE";
|
|
53
|
+
})(AclOperationTypes = exports.AclOperationTypes || (exports.AclOperationTypes = {}));
|
|
54
|
+
var ResourcePatternTypes;
|
|
55
|
+
(function (ResourcePatternTypes) {
|
|
56
|
+
ResourcePatternTypes[ResourcePatternTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
|
57
|
+
ResourcePatternTypes[ResourcePatternTypes["ANY"] = 1] = "ANY";
|
|
58
|
+
ResourcePatternTypes[ResourcePatternTypes["MATCH"] = 2] = "MATCH";
|
|
59
|
+
ResourcePatternTypes[ResourcePatternTypes["LITERAL"] = 3] = "LITERAL";
|
|
60
|
+
ResourcePatternTypes[ResourcePatternTypes["PREFIXED"] = 4] = "PREFIXED";
|
|
61
|
+
})(ResourcePatternTypes = exports.ResourcePatternTypes || (exports.ResourcePatternTypes = {}));
|
|
62
|
+
var logLevel;
|
|
63
|
+
(function (logLevel) {
|
|
64
|
+
logLevel[logLevel["NOTHING"] = 0] = "NOTHING";
|
|
65
|
+
logLevel[logLevel["ERROR"] = 1] = "ERROR";
|
|
66
|
+
logLevel[logLevel["WARN"] = 2] = "WARN";
|
|
67
|
+
logLevel[logLevel["INFO"] = 4] = "INFO";
|
|
68
|
+
logLevel[logLevel["DEBUG"] = 5] = "DEBUG";
|
|
69
|
+
})(logLevel = exports.logLevel || (exports.logLevel = {}));
|
|
70
|
+
var CompressionTypes;
|
|
71
|
+
(function (CompressionTypes) {
|
|
72
|
+
CompressionTypes[CompressionTypes["None"] = 0] = "None";
|
|
73
|
+
CompressionTypes[CompressionTypes["GZIP"] = 1] = "GZIP";
|
|
74
|
+
CompressionTypes[CompressionTypes["Snappy"] = 2] = "Snappy";
|
|
75
|
+
CompressionTypes[CompressionTypes["LZ4"] = 3] = "LZ4";
|
|
76
|
+
CompressionTypes[CompressionTypes["ZSTD"] = 4] = "ZSTD";
|
|
77
|
+
})(CompressionTypes = exports.CompressionTypes || (exports.CompressionTypes = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
export declare class MqttClient extends EventEmitter {
|
|
5
|
+
connected: boolean;
|
|
6
|
+
disconnecting: boolean;
|
|
7
|
+
disconnected: boolean;
|
|
8
|
+
reconnecting: boolean;
|
|
9
|
+
incomingStore: any;
|
|
10
|
+
outgoingStore: any;
|
|
11
|
+
options: any;
|
|
12
|
+
queueQoSZero: boolean;
|
|
13
|
+
constructor(streamBuilder: (client: MqttClient) => any, options: any);
|
|
14
|
+
on(event: 'message', cb: any): this;
|
|
15
|
+
on(event: 'packetsend' | 'packetreceive', cb: any): this;
|
|
16
|
+
on(event: 'error', cb: any): this;
|
|
17
|
+
on(event: string, cb: Function): this;
|
|
18
|
+
once(event: 'message', cb: any): this;
|
|
19
|
+
once(event: 'packetsend' | 'packetreceive', cb: any): this;
|
|
20
|
+
once(event: 'error', cb: any): this;
|
|
21
|
+
once(event: string, cb: Function): this;
|
|
22
|
+
publish(topic: string, message: string | Buffer, opts: any, callback?: any): this;
|
|
23
|
+
publish(topic: string, message: string | Buffer, callback?: any): this;
|
|
24
|
+
subscribe(topic: string | string[], opts: any, callback?: any): this;
|
|
25
|
+
subscribe(topic: string | string[] | any, callback?: any): this;
|
|
26
|
+
unsubscribe(topic: string | string[], callback?: any): this;
|
|
27
|
+
end(force?: boolean, cb?: any): this;
|
|
28
|
+
removeOutgoingMessage(mid: number): this;
|
|
29
|
+
reconnect(opts?: any): this;
|
|
30
|
+
handleMessage(packet: any, callback: any): void;
|
|
31
|
+
getLastMessageId(): number;
|
|
32
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare type QoS = 0 | 1 | 2;
|
|
3
|
+
export interface MqttClientOptions extends ISecureClientOptions {
|
|
4
|
+
port?: number;
|
|
5
|
+
host?: string;
|
|
6
|
+
hostname?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs';
|
|
9
|
+
wsOptions?: {
|
|
10
|
+
[x: string]: any;
|
|
11
|
+
};
|
|
12
|
+
keepalive?: number;
|
|
13
|
+
clientId?: string;
|
|
14
|
+
protocolId?: string;
|
|
15
|
+
protocolVersion?: number;
|
|
16
|
+
clean?: boolean;
|
|
17
|
+
reconnectPeriod?: number;
|
|
18
|
+
connectTimeout?: number;
|
|
19
|
+
username?: string;
|
|
20
|
+
password?: string;
|
|
21
|
+
incomingStore?: any;
|
|
22
|
+
outgoingStore?: any;
|
|
23
|
+
queueQoSZero?: boolean;
|
|
24
|
+
reschedulePings?: boolean;
|
|
25
|
+
servers?: Array<{
|
|
26
|
+
host: string;
|
|
27
|
+
port: number;
|
|
28
|
+
}>;
|
|
29
|
+
resubscribe?: boolean;
|
|
30
|
+
will?: {
|
|
31
|
+
topic: string;
|
|
32
|
+
payload: string;
|
|
33
|
+
qos: QoS;
|
|
34
|
+
retain: boolean;
|
|
35
|
+
};
|
|
36
|
+
transformWsUrl?: (url: string, options: any, client: any) => string;
|
|
37
|
+
}
|
|
38
|
+
export interface ISecureClientOptions {
|
|
39
|
+
key?: string | string[] | Buffer | Buffer[] | Record<string, any>[];
|
|
40
|
+
cert?: string | string[] | Buffer | Buffer[];
|
|
41
|
+
ca?: string | string[] | Buffer | Buffer[];
|
|
42
|
+
rejectUnauthorized?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface IClientPublishOptions {
|
|
45
|
+
qos: QoS;
|
|
46
|
+
retain?: boolean;
|
|
47
|
+
dup?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface IClientSubscribeOptions {
|
|
50
|
+
qos: QoS;
|
|
51
|
+
}
|
|
52
|
+
export interface IClientReconnectOptions {
|
|
53
|
+
incomingStore?: any;
|
|
54
|
+
outgoingStore?: any;
|
|
55
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ConnectionOptions } from 'tls';
|
|
3
|
+
export interface IORedisOptions {
|
|
4
|
+
Connector?: any;
|
|
5
|
+
retryStrategy?: (times: number) => number | void | null;
|
|
6
|
+
commandTimeout?: number;
|
|
7
|
+
keepAlive?: number;
|
|
8
|
+
noDelay?: boolean;
|
|
9
|
+
connectionName?: string;
|
|
10
|
+
username?: string;
|
|
11
|
+
password?: string;
|
|
12
|
+
db?: number;
|
|
13
|
+
autoResubscribe?: boolean;
|
|
14
|
+
autoResendUnfulfilledCommands?: boolean;
|
|
15
|
+
reconnectOnError?: ((err: Error) => boolean | 1 | 2) | null;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
stringNumbers?: boolean;
|
|
18
|
+
connectTimeout?: number;
|
|
19
|
+
monitor?: boolean;
|
|
20
|
+
maxRetriesPerRequest?: number | null;
|
|
21
|
+
maxLoadingRetryTime?: number;
|
|
22
|
+
enableAutoPipelining?: boolean;
|
|
23
|
+
autoPipeliningIgnoredCommands?: string[];
|
|
24
|
+
offlineQueue?: boolean;
|
|
25
|
+
commandQueue?: boolean;
|
|
26
|
+
enableOfflineQueue?: boolean;
|
|
27
|
+
enableReadyCheck?: boolean;
|
|
28
|
+
lazyConnect?: boolean;
|
|
29
|
+
scripts?: Record<string, {
|
|
30
|
+
lua: string;
|
|
31
|
+
numberOfKeys?: number;
|
|
32
|
+
readOnly?: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
keyPrefix?: string;
|
|
35
|
+
showFriendlyErrorStack?: boolean;
|
|
36
|
+
disconnectTimeout?: number;
|
|
37
|
+
tls?: ConnectionOptions;
|
|
38
|
+
name?: string;
|
|
39
|
+
role?: 'master' | 'slave';
|
|
40
|
+
sentinelUsername?: string;
|
|
41
|
+
sentinelPassword?: string;
|
|
42
|
+
sentinels?: Array<Partial<any>>;
|
|
43
|
+
sentinelRetryStrategy?: (retryAttempts: number) => number | void | null;
|
|
44
|
+
sentinelReconnectStrategy?: (retryAttempts: number) => number | void | null;
|
|
45
|
+
preferredSlaves?: any;
|
|
46
|
+
sentinelCommandTimeout?: number;
|
|
47
|
+
enableTLSForSentinelMode?: boolean;
|
|
48
|
+
sentinelTLS?: ConnectionOptions;
|
|
49
|
+
natMap?: any;
|
|
50
|
+
updateSentinels?: boolean;
|
|
51
|
+
sentinelMaxConnections?: number;
|
|
52
|
+
failoverDetector?: boolean;
|
|
53
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface RmqUrl {
|
|
2
|
+
protocol?: string;
|
|
3
|
+
hostname?: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
username?: string;
|
|
6
|
+
password?: string;
|
|
7
|
+
locale?: string;
|
|
8
|
+
frameMax?: number;
|
|
9
|
+
heartbeat?: number;
|
|
10
|
+
vhost?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AmqpConnectionManagerSocketOptions {
|
|
13
|
+
reconnectTimeInSeconds?: number;
|
|
14
|
+
heartbeatIntervalInSeconds?: number;
|
|
15
|
+
findServers?: () => string | string[];
|
|
16
|
+
connectionOptions?: any;
|
|
17
|
+
}
|
|
18
|
+
export interface AmqplibQueueOptions {
|
|
19
|
+
durable?: boolean;
|
|
20
|
+
autoDelete?: boolean;
|
|
21
|
+
arguments?: any;
|
|
22
|
+
messageTtl?: number;
|
|
23
|
+
expires?: number;
|
|
24
|
+
deadLetterExchange?: string;
|
|
25
|
+
deadLetterRoutingKey?: string;
|
|
26
|
+
maxLength?: number;
|
|
27
|
+
maxPriority?: number;
|
|
28
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,4 +21,5 @@ __exportStar(require("./decorator"), exports);
|
|
|
21
21
|
__exportStar(require("./enum"), exports);
|
|
22
22
|
__exportStar(require("./guard"), exports);
|
|
23
23
|
__exportStar(require("./module"), exports);
|
|
24
|
+
__exportStar(require("./server"), exports);
|
|
24
25
|
__exportStar(require("./strategy"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Server, CustomTransportStrategy, RmqOptions, RmqContext, Transport, ReadPacket } from '@nestjs/microservices';
|
|
2
|
+
import { RmqUrl } from '@nestjs/microservices/external/rmq-url.interface';
|
|
3
|
+
export declare class CustomServerRMQ extends Server implements CustomTransportStrategy {
|
|
4
|
+
protected readonly options: RmqOptions['options'];
|
|
5
|
+
readonly transportId = Transport.RMQ;
|
|
6
|
+
protected server: any;
|
|
7
|
+
protected channel: any;
|
|
8
|
+
protected connectionAttempts: number;
|
|
9
|
+
protected readonly urls: string[] | RmqUrl[];
|
|
10
|
+
protected readonly queue: string;
|
|
11
|
+
protected readonly prefetchCount: number;
|
|
12
|
+
protected readonly noAck: boolean;
|
|
13
|
+
protected readonly queueOptions: any;
|
|
14
|
+
protected readonly isGlobalPrefetchCount: boolean;
|
|
15
|
+
protected readonly noAssert: boolean;
|
|
16
|
+
constructor(options: RmqOptions['options']);
|
|
17
|
+
listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>;
|
|
18
|
+
close(): void;
|
|
19
|
+
start(callback?: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>;
|
|
20
|
+
createClient<T = any>(): T;
|
|
21
|
+
setupChannel(channel: any, callback: Function): Promise<void>;
|
|
22
|
+
handleMessage(message: Record<string, any>, channel: any, pattern: string): Promise<void>;
|
|
23
|
+
handleEvent(pattern: string, packet: ReadPacket, context: RmqContext): Promise<any>;
|
|
24
|
+
sendMessage<T = any>(message: T, replyTo: any, correlationId: string): void;
|
|
25
|
+
protected initializeSerializer(options: RmqOptions['options']): void;
|
|
26
|
+
private parseMessageContent;
|
|
27
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomServerRMQ = void 0;
|
|
4
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
6
|
+
const constants_1 = require("@nestjs/microservices/constants");
|
|
7
|
+
const rmq_record_serializer_1 = require("@nestjs/microservices/serializers/rmq-record.serializer");
|
|
8
|
+
const JSONbig = require("json-bigint");
|
|
9
|
+
let rqmPackage = {};
|
|
10
|
+
const INFINITE_CONNECTION_ATTEMPTS = -1;
|
|
11
|
+
class CustomServerRMQ extends microservices_1.Server {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super();
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.transportId = microservices_1.Transport.RMQ;
|
|
16
|
+
this.server = null;
|
|
17
|
+
this.channel = null;
|
|
18
|
+
this.connectionAttempts = 0;
|
|
19
|
+
this.urls = this.getOptionsProp(this.options, 'urls') || [constants_1.RQM_DEFAULT_URL];
|
|
20
|
+
this.queue =
|
|
21
|
+
this.getOptionsProp(this.options, 'queue') || constants_1.RQM_DEFAULT_QUEUE;
|
|
22
|
+
this.prefetchCount =
|
|
23
|
+
this.getOptionsProp(this.options, 'prefetchCount') ||
|
|
24
|
+
constants_1.RQM_DEFAULT_PREFETCH_COUNT;
|
|
25
|
+
this.noAck = this.getOptionsProp(this.options, 'noAck', constants_1.RQM_DEFAULT_NOACK);
|
|
26
|
+
this.isGlobalPrefetchCount =
|
|
27
|
+
this.getOptionsProp(this.options, 'isGlobalPrefetchCount') ||
|
|
28
|
+
constants_1.RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT;
|
|
29
|
+
this.queueOptions =
|
|
30
|
+
this.getOptionsProp(this.options, 'queueOptions') ||
|
|
31
|
+
constants_1.RQM_DEFAULT_QUEUE_OPTIONS;
|
|
32
|
+
this.noAssert =
|
|
33
|
+
this.getOptionsProp(this.options, 'noAssert') || constants_1.RQM_DEFAULT_NO_ASSERT;
|
|
34
|
+
this.loadPackage('amqplib', CustomServerRMQ.name, () => require('amqplib'));
|
|
35
|
+
rqmPackage = this.loadPackage('amqp-connection-manager', CustomServerRMQ.name, () => require('amqp-connection-manager'));
|
|
36
|
+
this.initializeSerializer(options);
|
|
37
|
+
this.initializeDeserializer(options);
|
|
38
|
+
}
|
|
39
|
+
async listen(callback) {
|
|
40
|
+
try {
|
|
41
|
+
await this.start(callback);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
callback(err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
close() {
|
|
48
|
+
this.channel && this.channel.close();
|
|
49
|
+
this.server && this.server.close();
|
|
50
|
+
}
|
|
51
|
+
async start(callback) {
|
|
52
|
+
this.server = this.createClient();
|
|
53
|
+
this.server.on(constants_1.CONNECT_EVENT, () => {
|
|
54
|
+
if (this.channel) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.channel = this.server.createChannel({
|
|
58
|
+
json: false,
|
|
59
|
+
setup: (channel) => this.setupChannel(channel, callback),
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
const maxConnectionAttempts = this.getOptionsProp(this.options, 'maxConnectionAttempts', INFINITE_CONNECTION_ATTEMPTS);
|
|
63
|
+
this.server.on(constants_1.DISCONNECT_EVENT, (err) => {
|
|
64
|
+
this.logger.error(constants_1.DISCONNECTED_RMQ_MESSAGE);
|
|
65
|
+
this.logger.error(err);
|
|
66
|
+
});
|
|
67
|
+
this.server.on(constants_1.CONNECT_FAILED_EVENT, (error) => {
|
|
68
|
+
var _a;
|
|
69
|
+
this.logger.error(constants_1.CONNECTION_FAILED_MESSAGE);
|
|
70
|
+
if (error === null || error === void 0 ? void 0 : error.err) {
|
|
71
|
+
this.logger.error(error.err);
|
|
72
|
+
}
|
|
73
|
+
const isReconnecting = !!this.channel;
|
|
74
|
+
if (maxConnectionAttempts === INFINITE_CONNECTION_ATTEMPTS ||
|
|
75
|
+
isReconnecting) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (++this.connectionAttempts === maxConnectionAttempts) {
|
|
79
|
+
this.close();
|
|
80
|
+
callback === null || callback === void 0 ? void 0 : callback((_a = error.err) !== null && _a !== void 0 ? _a : new Error(constants_1.CONNECTION_FAILED_MESSAGE));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
createClient() {
|
|
85
|
+
const socketOptions = this.getOptionsProp(this.options, 'socketOptions');
|
|
86
|
+
return rqmPackage.connect(this.urls, {
|
|
87
|
+
connectionOptions: socketOptions,
|
|
88
|
+
heartbeatIntervalInSeconds: socketOptions === null || socketOptions === void 0 ? void 0 : socketOptions.heartbeatIntervalInSeconds,
|
|
89
|
+
reconnectTimeInSeconds: socketOptions === null || socketOptions === void 0 ? void 0 : socketOptions.reconnectTimeInSeconds,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async setupChannel(channel, callback) {
|
|
93
|
+
if (!this.queueOptions.noAssert) {
|
|
94
|
+
await channel.assertQueue(this.queue, this.queueOptions);
|
|
95
|
+
}
|
|
96
|
+
await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);
|
|
97
|
+
channel.consume(this.queue, (msg) => this.handleMessage(msg, channel, this.queue), {
|
|
98
|
+
noAck: this.noAck,
|
|
99
|
+
});
|
|
100
|
+
callback();
|
|
101
|
+
}
|
|
102
|
+
async handleMessage(message, channel, pattern) {
|
|
103
|
+
var _a;
|
|
104
|
+
if ((0, shared_utils_1.isNil)(message)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const { content, properties } = message;
|
|
108
|
+
const rawMessage = this.parseMessageContent(content);
|
|
109
|
+
const packet = {
|
|
110
|
+
pattern: ((_a = message === null || message === void 0 ? void 0 : message.fields) === null || _a === void 0 ? void 0 : _a.routingKey) || pattern,
|
|
111
|
+
data: rawMessage,
|
|
112
|
+
};
|
|
113
|
+
const rmqContext = new microservices_1.RmqContext([message, channel, pattern]);
|
|
114
|
+
if ((0, shared_utils_1.isUndefined)(packet.id)) {
|
|
115
|
+
return this.handleEvent(pattern, packet, rmqContext);
|
|
116
|
+
}
|
|
117
|
+
const handler = this.getHandlerByPattern(pattern);
|
|
118
|
+
if (!handler) {
|
|
119
|
+
const status = 'error';
|
|
120
|
+
const noHandlerPacket = {
|
|
121
|
+
id: packet.id,
|
|
122
|
+
err: constants_1.NO_MESSAGE_HANDLER,
|
|
123
|
+
status,
|
|
124
|
+
};
|
|
125
|
+
return this.sendMessage(noHandlerPacket, properties.replyTo, properties.correlationId);
|
|
126
|
+
}
|
|
127
|
+
const response$ = this.transformToObservable(await handler(packet.data, rmqContext));
|
|
128
|
+
const publish = (data) => this.sendMessage(data, properties.replyTo, properties.correlationId);
|
|
129
|
+
response$ && this.send(response$, publish);
|
|
130
|
+
}
|
|
131
|
+
async handleEvent(pattern, packet, context) {
|
|
132
|
+
const handler = this.getHandlerByPattern(pattern);
|
|
133
|
+
if (!handler && !this.noAck) {
|
|
134
|
+
this.channel.nack(context.getMessage(), false, false);
|
|
135
|
+
return this.logger.warn((0, constants_1.RQM_NO_EVENT_HANDLER) `${pattern}`);
|
|
136
|
+
}
|
|
137
|
+
return super.handleEvent(pattern, packet, context);
|
|
138
|
+
}
|
|
139
|
+
sendMessage(message, replyTo, correlationId) {
|
|
140
|
+
const outgoingResponse = this.serializer.serialize(message);
|
|
141
|
+
const options = outgoingResponse.options;
|
|
142
|
+
delete outgoingResponse.options;
|
|
143
|
+
const buffer = Buffer.from(JSON.stringify(outgoingResponse));
|
|
144
|
+
this.channel.sendToQueue(replyTo, buffer, { correlationId, ...options });
|
|
145
|
+
}
|
|
146
|
+
initializeSerializer(options) {
|
|
147
|
+
var _a;
|
|
148
|
+
this.serializer = (_a = options === null || options === void 0 ? void 0 : options.serializer) !== null && _a !== void 0 ? _a : new rmq_record_serializer_1.RmqRecordSerializer();
|
|
149
|
+
}
|
|
150
|
+
parseMessageContent(content) {
|
|
151
|
+
try {
|
|
152
|
+
return JSONbig.parse(content.toString());
|
|
153
|
+
}
|
|
154
|
+
catch (_a) {
|
|
155
|
+
return content.toString();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.CustomServerRMQ = CustomServerRMQ;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerKeepAlive = exports.CustomServerRMQ = void 0;
|
|
4
|
+
const custom_server_rmq_1 = require("./custom-server-rmq");
|
|
5
|
+
Object.defineProperty(exports, "CustomServerRMQ", { enumerable: true, get: function () { return custom_server_rmq_1.CustomServerRMQ; } });
|
|
6
|
+
const server_keepalive_1 = require("./server-keepalive");
|
|
7
|
+
Object.defineProperty(exports, "ServerKeepAlive", { enumerable: true, get: function () { return server_keepalive_1.ServerKeepAlive; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerKeepAlive = void 0;
|
|
4
|
+
class ServerKeepAlive {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.closing = false;
|
|
7
|
+
}
|
|
8
|
+
wait() {
|
|
9
|
+
if (!this.closing) {
|
|
10
|
+
setTimeout(() => this.wait(), 1000);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
listen(callback) {
|
|
14
|
+
callback();
|
|
15
|
+
this.wait();
|
|
16
|
+
}
|
|
17
|
+
close() {
|
|
18
|
+
this.closing = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ServerKeepAlive = ServerKeepAlive;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
## this external folder is copy from "@nestjs/microservices" which not export any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-microservices",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.11",
|
|
4
4
|
"description": "nestjs-microservices",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"@nestjs/testing": "^9.4.3",
|
|
20
20
|
"@types/express": "^4.17.17",
|
|
21
21
|
"@types/jest": "^29.5.2",
|
|
22
|
+
"@types/json-bigint": "^1.0.1",
|
|
22
23
|
"@types/node": "^17.0.22",
|
|
23
24
|
"@types/passport-jwt": "^3.0.8",
|
|
24
25
|
"@types/supertest": "^2.0.12",
|
|
@@ -43,15 +44,50 @@
|
|
|
43
44
|
"@nathapp/nestjs-auth": "^1.0.0-rc.23",
|
|
44
45
|
"@nathapp/nestjs-common": "^1.0.1-rc.16",
|
|
45
46
|
"axios": "^1.4.0",
|
|
47
|
+
"json-bigint": "^1.0.0",
|
|
46
48
|
"passport-jwt": "^4.0.1"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
51
|
+
"@grpc/grpc-js": "*",
|
|
49
52
|
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
50
53
|
"@nestjs/config": "^1.0.0 || ^2.0.0 || ^3.0.0",
|
|
51
54
|
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
55
|
+
"@nestjs/microservices": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
52
56
|
"@nestjs/passport": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
57
|
+
"amqp-connection-manager": "*",
|
|
58
|
+
"amqplib": "*",
|
|
53
59
|
"class-transformer": "*",
|
|
54
60
|
"class-validator": "*",
|
|
61
|
+
"ioredis": "*",
|
|
62
|
+
"kafkajs": "*",
|
|
63
|
+
"mqtt": "*",
|
|
64
|
+
"nats": "*",
|
|
55
65
|
"rxjs": "*"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"@grpc/grpc-js": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"@nestjs/websockets": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"kafkajs": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"mqtt": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"nats": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"ioredis": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"amqplib": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"amqp-connection-manager": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
56
92
|
}
|
|
57
93
|
}
|