-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathmicroservice-configuration.interface.ts
339 lines (327 loc) · 8.63 KB
/
microservice-configuration.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import { InjectionToken, Type } from '@nestjs/common';
import { TlsOptions } from 'tls';
import { Transport } from '../enums/transport.enum';
import { ChannelOptions } from '../external/grpc-options.interface';
import {
ConsumerConfig,
ConsumerRunConfig,
ConsumerSubscribeTopics,
KafkaConfig,
ProducerConfig,
ProducerRecord,
} from '../external/kafka.interface';
import { MqttClientOptions, QoS } from '../external/mqtt-options.interface';
import { IORedisOptions } from '../external/redis.interface';
import {
AmqpConnectionManagerSocketOptions,
AmqplibQueueOptions,
RmqUrl,
} from '../external/rmq-url.interface';
import { TcpSocket } from '../helpers';
import { CustomTransportStrategy } from './custom-transport-strategy.interface';
import { Deserializer } from './deserializer.interface';
import { Serializer } from './serializer.interface';
export type MicroserviceOptions =
| GrpcOptions
| TcpOptions
| RedisOptions
| NatsOptions
| MqttOptions
| RmqOptions
| KafkaOptions
| CustomStrategy;
export type AsyncMicroserviceOptions = {
inject: InjectionToken[];
useFactory: (...args: any[]) => MicroserviceOptions;
};
export type AsyncOptions<T extends object> = {
inject: InjectionToken[];
useFactory: (...args: any[]) => T;
};
/**
* @publicApi
*/
export interface CustomStrategy {
strategy: CustomTransportStrategy;
options?: Record<string, any>;
}
/**
* @publicApi
*/
export interface GrpcOptions {
transport?: Transport.GRPC;
options: {
url?: string;
maxSendMessageLength?: number;
maxReceiveMessageLength?: number;
maxMetadataSize?: number;
keepalive?: {
keepaliveTimeMs?: number;
keepaliveTimeoutMs?: number;
keepalivePermitWithoutCalls?: number;
http2MaxPingsWithoutData?: number;
http2MinTimeBetweenPingsMs?: number;
http2MinPingIntervalWithoutDataMs?: number;
http2MaxPingStrikes?: number;
};
channelOptions?: ChannelOptions;
credentials?: any;
protoPath?: string | string[];
package: string | string[];
protoLoader?: string;
packageDefinition?: any;
gracefulShutdown?: boolean;
onLoadPackageDefinition?: (pkg: any, server: any) => void;
loader?: {
keepCase?: boolean;
alternateCommentMode?: boolean;
longs?: Function;
enums?: Function;
bytes?: Function;
defaults?: boolean;
arrays?: boolean;
objects?: boolean;
oneofs?: boolean;
json?: boolean;
includeDirs?: string[];
};
};
}
/**
* @publicApi
*/
export interface TcpOptions {
transport?: Transport.TCP;
options?: {
host?: string;
port?: number;
retryAttempts?: number;
retryDelay?: number;
serializer?: Serializer;
tlsOptions?: TlsOptions;
deserializer?: Deserializer;
socketClass?: Type<TcpSocket>;
};
}
/**
* @publicApi
*/
export interface RedisOptions {
transport?: Transport.REDIS;
options?: {
host?: string;
port?: number;
retryAttempts?: number;
retryDelay?: number;
/**
* Use `psubscribe`/`pmessage` to enable wildcards in the patterns
*/
wildcards?: boolean;
serializer?: Serializer;
deserializer?: Deserializer;
} & IORedisOptions;
}
/**
* @publicApi
*/
export interface MqttOptions {
transport?: Transport.MQTT;
options?: MqttClientOptions & {
url?: string;
serializer?: Serializer;
deserializer?: Deserializer;
subscribeOptions?: {
/**
* The QoS
*/
qos: QoS;
/*
* No local flag
* */
nl?: boolean;
/*
* Retain as Published flag
* */
rap?: boolean;
/*
* Retain Handling option
* */
rh?: number;
};
userProperties?: Record<string, string | string[]>;
};
}
/**
* @publicApi
*/
export interface NatsOptions {
transport?: Transport.NATS;
options?: {
headers?: Record<string, string>;
authenticator?: any;
debug?: boolean;
ignoreClusterUpdates?: boolean;
inboxPrefix?: string;
encoding?: string;
name?: string;
user?: string;
pass?: string;
maxPingOut?: number;
maxReconnectAttempts?: number;
reconnectTimeWait?: number;
reconnectJitter?: number;
reconnectJitterTLS?: number;
reconnectDelayHandler?: any;
servers?: string[] | string;
nkey?: any;
reconnect?: boolean;
pedantic?: boolean;
tls?: any;
queue?: string;
serializer?: Serializer;
deserializer?: Deserializer;
userJWT?: string;
nonceSigner?: any;
userCreds?: any;
useOldRequestStyle?: boolean;
pingInterval?: number;
preserveBuffers?: boolean;
waitOnFirstConnect?: boolean;
verbose?: boolean;
noEcho?: boolean;
noRandomize?: boolean;
timeout?: number;
token?: string;
yieldTime?: number;
tokenHandler?: any;
gracefulShutdown?: boolean;
gracePeriod?: number;
[key: string]: any;
};
}
/**
* @publicApi
*/
export interface RmqOptions {
transport?: Transport.RMQ;
options?: {
/**
* An array of connection URLs to try in order.
*/
urls?: string[] | RmqUrl[];
/**
* The name of the queue.
*/
queue?: string;
/**
* A prefetch count for this channel. The count given is the maximum number of messages sent over the channel that can be awaiting acknowledgement;
* once there are count messages outstanding, the server will not send more messages on this channel until one or more have been acknowledged.
*/
prefetchCount?: number;
/**
* Sets the per-channel behavior for prefetching messages.
*/
isGlobalPrefetchCount?: boolean;
/**
* Amqplib queue options.
* @see https://amqp-node.github.io/amqplib/channel_api.html#channel_assertQueue
*/
queueOptions?: AmqplibQueueOptions;
/**
* AMQP Connection Manager socket options.
*/
socketOptions?: AmqpConnectionManagerSocketOptions;
/**
* Iif true, the broker won’t expect an acknowledgement of messages delivered to this consumer; i.e., it will dequeue messages as soon as they’ve been sent down the wire.
* @default false
*/
noAck?: boolean;
/**
* A name which the server will use to distinguish message deliveries for the consumer; mustn’t be already in use on the channel. It’s usually easier to omit this, in which case the server will create a random name and supply it in the reply.
*/
consumerTag?: string;
/**
* A serializer for the message payload.
*/
serializer?: Serializer;
/**
* A deserializer for the message payload.
*/
deserializer?: Deserializer;
/**
* A reply queue for the producer.
* @default 'amq.rabbitmq.reply-to'
*/
replyQueue?: string;
/**
* If truthy, the message will survive broker restarts provided it’s in a queue that also survives restarts.
*/
persistent?: boolean;
/**
* Additional headers to be sent with every message.
* Applies only to the producer configuration.
*/
headers?: Record<string, string>;
/**
* When false, a queue will not be asserted before consuming.
* @default false
*/
noAssert?: boolean;
/**
* Name for the exchange. Defaults to the queue name when "wildcards" is set to true.
* @default ''
*/
exchange?: string;
/**
* Type of the exchange
* @default 'topic'
*/
exchangeType?: 'direct' | 'fanout' | 'topic' | 'headers';
/**
* Additional routing key for the topic exchange.
*/
routingKey?: string;
/**
* Set to true only if you want to use Topic Exchange for routing messages to queues.
* Enabling this will allow you to use wildcards (*, #) as message and event patterns.
* @see https://www.rabbitmq.com/tutorials/tutorial-five-python#topic-exchange
* @default false
*/
wildcards?: boolean;
/**
* Maximum number of connection attempts.
* Applies only to the consumer configuration.
* -1 === infinite
* @default -1
*/
maxConnectionAttempts?: number;
};
}
/**
* @publicApi
*/
export interface KafkaParserConfig {
keepBinary?: boolean;
}
/**
* @publicApi
*/
export interface KafkaOptions {
transport?: Transport.KAFKA;
options?: {
/**
* Defaults to `"-server"` on server side and `"-client"` on client side.
*/
postfixId?: string;
client?: KafkaConfig;
consumer?: ConsumerConfig;
run?: Omit<ConsumerRunConfig, 'eachBatch' | 'eachMessage'>;
subscribe?: Omit<ConsumerSubscribeTopics, 'topics'>;
producer?: ProducerConfig;
send?: Omit<ProducerRecord, 'topic' | 'messages'>;
serializer?: Serializer;
deserializer?: Deserializer;
parser?: KafkaParserConfig;
producerOnlyMode?: boolean;
};
}