1 |
|
2 | import { Type } from '@nestjs/common';
|
3 | import { ConnectionOptions } from 'tls';
|
4 | import { Transport } from '../enums/transport.enum';
|
5 | import { ChannelOptions } from '../external/grpc-options.interface';
|
6 | import { ConsumerConfig, ConsumerRunConfig, ConsumerSubscribeTopics, KafkaConfig, ProducerConfig, ProducerRecord } from '../external/kafka.interface';
|
7 | import { MqttClientOptions, QoS } from '../external/mqtt-options.interface';
|
8 | import { IORedisOptions } from '../external/redis.interface';
|
9 | import { RmqUrl } from '../external/rmq-url.interface';
|
10 | import { TcpSocket } from '../helpers';
|
11 | import { CustomTransportStrategy } from './custom-transport-strategy.interface';
|
12 | import { Deserializer } from './deserializer.interface';
|
13 | import { Serializer } from './serializer.interface';
|
14 | export type MicroserviceOptions = GrpcOptions | TcpOptions | RedisOptions | NatsOptions | MqttOptions | RmqOptions | KafkaOptions | CustomStrategy;
|
15 |
|
16 |
|
17 |
|
18 | export interface CustomStrategy {
|
19 | strategy: CustomTransportStrategy;
|
20 | options?: {};
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 | export interface GrpcOptions {
|
26 | transport?: Transport.GRPC;
|
27 | options: {
|
28 | url?: string;
|
29 | maxSendMessageLength?: number;
|
30 | maxReceiveMessageLength?: number;
|
31 | maxMetadataSize?: number;
|
32 | keepalive?: {
|
33 | keepaliveTimeMs?: number;
|
34 | keepaliveTimeoutMs?: number;
|
35 | keepalivePermitWithoutCalls?: number;
|
36 | http2MaxPingsWithoutData?: number;
|
37 | http2MinTimeBetweenPingsMs?: number;
|
38 | http2MinPingIntervalWithoutDataMs?: number;
|
39 | http2MaxPingStrikes?: number;
|
40 | };
|
41 | channelOptions?: ChannelOptions;
|
42 | credentials?: any;
|
43 | protoPath: string | string[];
|
44 | package: string | string[];
|
45 | protoLoader?: string;
|
46 | packageDefinition?: any;
|
47 | gracefulShutdown?: boolean;
|
48 | loader?: {
|
49 | keepCase?: boolean;
|
50 | alternateCommentMode?: boolean;
|
51 | longs?: Function;
|
52 | enums?: Function;
|
53 | bytes?: Function;
|
54 | defaults?: boolean;
|
55 | arrays?: boolean;
|
56 | objects?: boolean;
|
57 | oneofs?: boolean;
|
58 | json?: boolean;
|
59 | includeDirs?: string[];
|
60 | };
|
61 | };
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 | export interface TcpOptions {
|
67 | transport?: Transport.TCP;
|
68 | options?: {
|
69 | host?: string;
|
70 | port?: number;
|
71 | retryAttempts?: number;
|
72 | retryDelay?: number;
|
73 | serializer?: Serializer;
|
74 | tlsOptions?: ConnectionOptions;
|
75 | deserializer?: Deserializer;
|
76 | socketClass?: Type<TcpSocket>;
|
77 | };
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 | export interface RedisOptions {
|
83 | transport?: Transport.REDIS;
|
84 | options?: {
|
85 | host?: string;
|
86 | port?: number;
|
87 | retryAttempts?: number;
|
88 | retryDelay?: number;
|
89 | |
90 |
|
91 |
|
92 | wildcards?: boolean;
|
93 | serializer?: Serializer;
|
94 | deserializer?: Deserializer;
|
95 | } & IORedisOptions;
|
96 | }
|
97 |
|
98 |
|
99 |
|
100 | export interface MqttOptions {
|
101 | transport?: Transport.MQTT;
|
102 | options?: MqttClientOptions & {
|
103 | url?: string;
|
104 | serializer?: Serializer;
|
105 | deserializer?: Deserializer;
|
106 | subscribeOptions?: {
|
107 | |
108 |
|
109 |
|
110 | qos: QoS;
|
111 | nl?: boolean;
|
112 | rap?: boolean;
|
113 | rh?: number;
|
114 | };
|
115 | userProperties?: Record<string, string | string[]>;
|
116 | };
|
117 | }
|
118 |
|
119 |
|
120 |
|
121 | export interface NatsOptions {
|
122 | transport?: Transport.NATS;
|
123 | options?: {
|
124 | headers?: Record<string, string>;
|
125 | authenticator?: any;
|
126 | debug?: boolean;
|
127 | ignoreClusterUpdates?: boolean;
|
128 | inboxPrefix?: string;
|
129 | encoding?: string;
|
130 | name?: string;
|
131 | user?: string;
|
132 | pass?: string;
|
133 | maxPingOut?: number;
|
134 | maxReconnectAttempts?: number;
|
135 | reconnectTimeWait?: number;
|
136 | reconnectJitter?: number;
|
137 | reconnectJitterTLS?: number;
|
138 | reconnectDelayHandler?: any;
|
139 | servers?: string[] | string;
|
140 | nkey?: any;
|
141 | reconnect?: boolean;
|
142 | pedantic?: boolean;
|
143 | tls?: any;
|
144 | queue?: string;
|
145 | serializer?: Serializer;
|
146 | deserializer?: Deserializer;
|
147 | userJWT?: string;
|
148 | nonceSigner?: any;
|
149 | userCreds?: any;
|
150 | useOldRequestStyle?: boolean;
|
151 | pingInterval?: number;
|
152 | preserveBuffers?: boolean;
|
153 | waitOnFirstConnect?: boolean;
|
154 | verbose?: boolean;
|
155 | noEcho?: boolean;
|
156 | noRandomize?: boolean;
|
157 | timeout?: number;
|
158 | token?: string;
|
159 | yieldTime?: number;
|
160 | tokenHandler?: any;
|
161 | [key: string]: any;
|
162 | };
|
163 | }
|
164 |
|
165 |
|
166 |
|
167 | export interface RmqOptions {
|
168 | transport?: Transport.RMQ;
|
169 | options?: {
|
170 | urls?: string[] | RmqUrl[];
|
171 | queue?: string;
|
172 | prefetchCount?: number;
|
173 | isGlobalPrefetchCount?: boolean;
|
174 | queueOptions?: any;
|
175 | socketOptions?: any;
|
176 | noAck?: boolean;
|
177 | consumerTag?: string;
|
178 | serializer?: Serializer;
|
179 | deserializer?: Deserializer;
|
180 | replyQueue?: string;
|
181 | persistent?: boolean;
|
182 | headers?: Record<string, string>;
|
183 | noAssert?: boolean;
|
184 | |
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | maxConnectionAttempts?: number;
|
191 | };
|
192 | }
|
193 |
|
194 |
|
195 |
|
196 | export interface KafkaParserConfig {
|
197 | keepBinary?: boolean;
|
198 | }
|
199 |
|
200 |
|
201 |
|
202 | export interface KafkaOptions {
|
203 | transport?: Transport.KAFKA;
|
204 | options?: {
|
205 | |
206 |
|
207 |
|
208 | postfixId?: string;
|
209 | client?: KafkaConfig;
|
210 | consumer?: ConsumerConfig;
|
211 | run?: Omit<ConsumerRunConfig, 'eachBatch' | 'eachMessage'>;
|
212 | subscribe?: Omit<ConsumerSubscribeTopics, 'topics'>;
|
213 | producer?: ProducerConfig;
|
214 | send?: Omit<ProducerRecord, 'topic' | 'messages'>;
|
215 | serializer?: Serializer;
|
216 | deserializer?: Deserializer;
|
217 | parser?: KafkaParserConfig;
|
218 | producerOnlyMode?: boolean;
|
219 | };
|
220 | }
|