-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschema.js
326 lines (257 loc) · 9.2 KB
/
schema.js
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
const baseJoi = require('joi');
const recoverySchema = require('./utils/recovery').schema;
const Joi = baseJoi.extend((joi) => ({
type: 'coercedArray',
base: joi.alternatives().try(
joi.array().items(joi.string()).unique(),
joi.string()
),
validate(value) {
if (typeof value === 'string') {
return { value: [value] };
}
return { value };
},
}));
const exchangeTypes = Joi.string()
.valid('direct', 'topic', 'headers', 'fanout');
exports.Joi = Joi;
exports.schema = Joi
.object({
name: Joi.string()
.description('name of the service when advertising to AMQP')
.default('amqp'),
private: Joi.boolean()
.description('when true - initializes private queue right away')
.default(false),
cache: Joi.number().min(0)
.description('size of LRU cache for responses, 0 to disable it')
.default(100),
timeout: Joi.number()
.description('default *AndWait timeout')
.default(10000),
debug: Joi.boolean()
.description('enables debug messages')
.default(process.env.NODE_ENV !== 'production'),
listen: Joi.coercedArray()
.description('attach default queue to these routes on default exchange'),
version: Joi.string()
.description('advertise end-client service version')
.default('n/a'),
neck: Joi.number().min(0)
.description('if defined - queues will enter QoS mode with required ack & prefetch size of neck'),
noAck: Joi.boolean()
.description('allow setting auto-ack when neck is defined'),
tracer: Joi.object(),
connection: Joi
.object({
host: Joi.alternatives()
.try(
Joi.string(),
Joi.array().min(1).items(Joi.string()),
Joi.array().min(1).items(Joi.object({
host: Joi.string().required(),
port: Joi.number().required(),
}))
)
.description('rabbitmq host')
.default('localhost'),
port: Joi.number()
.description('rabbitmq port')
.default(5672),
heartbeat: Joi.number()
.description('heartbeat check')
.default(10000),
login: Joi.string()
.description('rabbitmq login')
.default('guest'),
password: Joi.string()
.description('rabbitmq password')
.default('guest'),
vhost: Joi.string()
.description('rabbitmq virtual host')
.default('/'),
temporaryChannelTimeout: Joi.number()
.description('temporary channel close time with no activity')
.default(6000),
reconnect: Joi.boolean()
.description('enable auto-reconnect')
.default(true),
reconnectDelayTime: Joi.number()
.description('reconnect delay time')
.default(500),
hostRandom: Joi.boolean()
.description('select host to connect to randomly')
.default(false),
ssl: Joi.boolean()
.description('whether to use SSL')
.default(false),
sslOptions: Joi.object()
.description('ssl options'),
noDelay: Joi.boolean()
.description('disable Nagle\'s algorithm')
.default(true),
clientProperties: Joi
.object({
capabilities: Joi.object({
consumer_cancel_notify: Joi.boolean()
.description('whether to react to cancel events')
.default(true),
}).default(),
})
.description('options for advertising client properties')
.default(),
})
.description('options for setting up connection to RabbitMQ')
.default(),
recovery: recoverySchema
.description('recovery settings')
.default(),
exchange: Joi.string()
.allow('')
.description('default exchange for communication')
.default('node-services'),
exchangeArgs: Joi
.object({
autoDelete: Joi.boolean()
.description('do not autoDelete exchanges')
.default(false),
noWait: Joi.boolean()
.description('whether not to wait for declare response')
.default(false),
internal: Joi.boolean()
.description('whether to set internal bit')
.default(false),
type: exchangeTypes
.description('type of the exchange')
.default('topic'),
durable: Joi.boolean()
.description('whether to preserve exchange on rabbitmq restart')
.default(true),
})
.default(),
bindPersistantQueueToHeadersExchange: Joi.boolean()
.description('whether to bind queues created by .createConsumedQueue to headersExchange')
.default(false),
headersExchange: Joi
.object({
exchange: Joi.string()
.description('default headers exchange to use, should be different from DLX headers exchange')
.default('amq.match'),
autoDelete: Joi.boolean()
.description('do not autoDelete exchanges')
.default(false),
noWait: Joi.boolean()
.description('whether not to wait for declare response')
.default(false),
internal: Joi.boolean()
.description('whether to set internal bit')
.default(false),
type: Joi.string()
.valid('headers')
.description('type of the exchange')
.default('headers'),
durable: Joi.boolean()
.description('whether to preserve exchange on rabbitmq restart')
.default(true),
})
.description('this exchange is used to support delayed retry with QoS exchanges')
.default(),
queue: Joi.string()
.description('default queue to connect to for consumption'),
defaultQueueOpts: Joi
.object({
autoDelete: Joi.boolean(),
exclusive: Joi.boolean(),
noWait: Joi.boolean(),
passive: Joi.boolean(),
durable: Joi.boolean()
.description('survive restarts & use disk storage')
.default(true),
arguments: Joi
.object({
'x-expires': Joi.number().min(0)
.description('delete queue after it\'s been unused for X seconds'),
'x-max-priority': Joi.number().min(2).max(255)
.description('setup priority queues where messages will be delivery based on priority level'),
})
.default(),
})
.description('default options for creating consumer queues')
.default(),
privateQueueOpts: Joi
.object({
autoDelete: Joi.boolean(),
exclusive: Joi.boolean(),
noWait: Joi.boolean(),
passive: Joi.boolean(),
durable: Joi.boolean()
.description('survive restarts & use disk storage')
.default(true),
arguments: Joi
.object({
'x-expires': Joi.number().min(0)
.description('delete the private queue after it\'s been unused for 3 minutes')
.default(1800000),
'x-max-priority': Joi.number().min(2).max(255)
.description('setup priority queues where messages will be delivery based on priority level'),
})
.default(),
})
.description('default options for private RPC queues')
.default(),
dlx: Joi
.object({
enabled: Joi.boolean()
.description('enabled DLX by default for fast-reply when messages are dropped')
.default(true),
params: Joi
.object({
exchange: Joi.string()
.description('dead letters are redirected here')
.default('amq.headers'),
type: exchangeTypes
.description('must be headers for proper built-in matching')
.default('headers'),
autoDelete: Joi.boolean()
.description('DLX persistance')
.default(false),
})
.default(),
})
.description('default for dead-letter-exchange')
.default(),
defaultOpts: Joi
.object({
deliveryMode: Joi.number().valid(1, 2)
.description('1 - transient, 2 - saved on disk')
.default(1),
confirm: Joi.boolean()
.description('whether to wait for commit confirmation')
.default(false),
mandatory: Joi.boolean()
.description('when true and message cant be routed to a queue - exception returned, otherwise its dropped')
.default(false),
immediate: Joi.boolean()
.description('not implemented by rabbitmq')
.default(false),
contentType: Joi.string()
.default('application/json')
.description('default content-type for messages'),
contentEncoding: Joi.string()
.default('plain')
.description('default content-encoding'),
headers: Joi.object()
.default(),
simpleResponse: Joi.boolean()
.description('whether to return only response data or include headers etc.')
.default(true),
})
.description('default options when publishing messages')
.default(),
})
.assert(
'.dlx.params.exchange',
Joi.any().invalid(Joi.ref('headersExchange.exchange')),
'must use different headers exchanges'
);