/
queueResourceSerializer.ts
606 lines (529 loc) · 19 KB
/
queueResourceSerializer.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { HttpOperationResponse, OperationOptions } from "@azure/core-http";
import {
AtomXmlSerializer,
deserializeAtomXmlResponse,
serializeToAtomXmlRequest
} from "../util/atomXmlHelper";
import * as Constants from "../util/constants";
import {
AuthorizationRule,
getAuthorizationRulesOrUndefined,
getBoolean,
getMessageCountDetails,
getInteger,
getIntegerOrUndefined,
getRawAuthorizationRules,
getString,
getStringOrUndefined,
getDate,
EntityStatus
} from "../util/utils";
/**
* @internal
* @ignore
* Builds the queue options object from the user provided options.
* Handles the differences in casing for the property names,
* converts values to string and ensures the right order as expected by the service
* @param queue
*/
export function buildQueueOptions(queue: CreateQueueOptions): InternalQueueOptions {
return {
LockDuration: queue.lockDuration,
MaxSizeInMegabytes: getStringOrUndefined(queue.maxSizeInMegabytes),
RequiresDuplicateDetection: getStringOrUndefined(queue.requiresDuplicateDetection),
RequiresSession: getStringOrUndefined(queue.requiresSession),
DefaultMessageTimeToLive: queue.defaultMessageTimeToLive,
DeadLetteringOnMessageExpiration: getStringOrUndefined(queue.deadLetteringOnMessageExpiration),
DuplicateDetectionHistoryTimeWindow: queue.duplicateDetectionHistoryTimeWindow,
MaxDeliveryCount: getStringOrUndefined(queue.maxDeliveryCount),
EnableBatchedOperations: getStringOrUndefined(queue.enableBatchedOperations),
AuthorizationRules: getRawAuthorizationRules(queue.authorizationRules),
Status: getStringOrUndefined(queue.status),
AutoDeleteOnIdle: getStringOrUndefined(queue.autoDeleteOnIdle),
EnablePartitioning: getStringOrUndefined(queue.enablePartitioning),
ForwardDeadLetteredMessagesTo: getStringOrUndefined(queue.forwardDeadLetteredMessagesTo),
ForwardTo: getStringOrUndefined(queue.forwardTo),
UserMetadata: getStringOrUndefined(queue.userMetadata),
EnableExpress: getStringOrUndefined(queue.enableExpress)
};
}
/**
* @internal
* @ignore
* Builds the queue object from the raw json object gotten after deserializing the
* response from the service
* @param rawQueue
*/
export function buildQueue(rawQueue: any): QueueProperties {
return {
name: getString(rawQueue[Constants.QUEUE_NAME], "queueName"),
forwardTo: getStringOrUndefined(rawQueue[Constants.FORWARD_TO]),
userMetadata: rawQueue[Constants.USER_METADATA],
lockDuration: getString(rawQueue[Constants.LOCK_DURATION], "lockDuration"),
maxSizeInMegabytes: getInteger(rawQueue[Constants.MAX_SIZE_IN_MEGABYTES], "maxSizeInMegabytes"),
maxDeliveryCount: getInteger(rawQueue[Constants.MAX_DELIVERY_COUNT], "maxDeliveryCount"),
enablePartitioning: getBoolean(rawQueue[Constants.ENABLE_PARTITIONING], "enablePartitioning"),
requiresSession: getBoolean(rawQueue[Constants.REQUIRES_SESSION], "requiresSession"),
enableBatchedOperations: getBoolean(
rawQueue[Constants.ENABLE_BATCHED_OPERATIONS],
"enableBatchedOperations"
),
defaultMessageTimeToLive: getString(
rawQueue[Constants.DEFAULT_MESSAGE_TIME_TO_LIVE],
"defaultMessageTimeToLive"
),
autoDeleteOnIdle: rawQueue[Constants.AUTO_DELETE_ON_IDLE],
requiresDuplicateDetection: getBoolean(
rawQueue[Constants.REQUIRES_DUPLICATE_DETECTION],
"requiresDuplicateDetection"
),
duplicateDetectionHistoryTimeWindow: getString(
rawQueue[Constants.DUPLICATE_DETECTION_HISTORY_TIME_WINDOW],
"duplicateDetectionHistoryTimeWindow"
),
deadLetteringOnMessageExpiration: getBoolean(
rawQueue[Constants.DEAD_LETTERING_ON_MESSAGE_EXPIRATION],
"deadLetteringOnMessageExpiration"
),
forwardDeadLetteredMessagesTo: getStringOrUndefined(
rawQueue[Constants.FORWARD_DEADLETTERED_MESSAGES_TO]
),
authorizationRules: getAuthorizationRulesOrUndefined(rawQueue[Constants.AUTHORIZATION_RULES]),
status: rawQueue[Constants.STATUS],
enableExpress: getBoolean(rawQueue[Constants.ENABLE_EXPRESS], "enableExpress")
};
}
/**
* @internal
* @ignore
* Builds the queue runtime info object from the raw json object gotten after deserializing the
* response from the service
* @param rawQueue
*/
export function buildQueueRuntimeProperties(rawQueue: any): QueueRuntimeProperties {
const messageCountDetails = getMessageCountDetails(rawQueue[Constants.COUNT_DETAILS]);
return {
name: getString(rawQueue[Constants.QUEUE_NAME], "queueName"),
sizeInBytes: getIntegerOrUndefined(rawQueue[Constants.SIZE_IN_BYTES]),
totalMessageCount: getIntegerOrUndefined(rawQueue[Constants.MESSAGE_COUNT]),
...messageCountDetails,
createdAt: getDate(rawQueue[Constants.CREATED_AT], "createdAt"),
modifiedAt: getDate(rawQueue[Constants.UPDATED_AT], "modifiedAt"),
accessedAt: getDate(rawQueue[Constants.ACCESSED_AT], "accessedAt")
};
}
/**
* Represents settable options on a queue
*/
export interface CreateQueueOptions extends OperationOptions {
/**
* Determines the amount of time in seconds in which a message should be locked for
* processing by a receiver. After this period, the message is unlocked and available
* for consumption by the next receiver. Settable only at queue creation time.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
lockDuration?: string;
/**
* Specifies the maximum queue size in megabytes. Any attempt to enqueue a message that
* will cause the queue to exceed this value will fail.
*/
maxSizeInMegabytes?: number;
/**
* If enabled, the topic will detect duplicate messages within the time
* span specified by the DuplicateDetectionHistoryTimeWindow property.
* Settable only at queue creation time.
*/
requiresDuplicateDetection?: boolean;
/**
* If set to true, the queue will be session-aware and only SessionReceiver
* will be supported. Session-aware queues are not supported through REST.
* Settable only at queue creation time.
*/
requiresSession?: boolean;
/**
* Depending on whether DeadLettering is enabled, a message is automatically
* moved to the dead-letter sub-queue or deleted if it has been stored in the
* queue for longer than the specified time.
* This value is overwritten by a TTL specified on the message
* if and only if the message TTL is smaller than the TTL set on the queue.
* This value is immutable after the Queue has been created.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
defaultMessageTimeToLive?: string;
/**
* If it is enabled and a message expires, the Service Bus moves the message
* from the queue into the queue’s dead-letter sub-queue. If disabled,
* message will be permanently deleted from the queue.
* Settable only at queue creation time.
*/
deadLetteringOnMessageExpiration?: boolean;
/**
* Specifies the time span during which the Service Bus detects message duplication.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
duplicateDetectionHistoryTimeWindow?: string;
/**
* The maximum delivery count of messages after which if it is still not settled,
* gets moved to the dead-letter sub-queue.
*/
maxDeliveryCount?: number;
/**
* Specifies if batched operations should be allowed.
*/
enableBatchedOperations?: boolean;
/**
* Authorization rules on the queue
*/
authorizationRules?: AuthorizationRule[];
/**
* Status of the messaging entity.
*/
status?: EntityStatus;
/**
* Absolute URL or the name of the queue or topic the
* messages are to be forwarded to.
* For example, an absolute URL input would be of the form
* `sb://<your-service-bus-namespace-endpoint>/<queue-or-topic-name>`
*/
forwardTo?: string;
/**
* The user provided metadata information associated with the queue.
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
userMetadata?: string;
/**
* Max idle time before entity is deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
autoDeleteOnIdle?: string;
/**
* Specifies whether the queue should be partitioned.
*/
enablePartitioning?: boolean;
/**
* Absolute URL or the name of the queue or topic the dead-lettered
* messages are to be forwarded to.
* For example, an absolute URL input would be of the form
* `sb://<your-service-bus-namespace-endpoint>/<queue-or-topic-name>`
*/
forwardDeadLetteredMessagesTo?: string;
/**
* Specifies whether express entities are enabled on queue.
*/
enableExpress?: boolean;
}
/**
* Represents the input for updateQueue.
*
* @export
* @interface QueueProperties
*/
export interface QueueProperties {
/**
* Name of the queue
*/
readonly name: string;
/**
* Determines the amount of time in seconds in which a message should be locked for
* processing by a receiver. After this period, the message is unlocked and available
* for consumption by the next receiver. Settable only at queue creation time.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
lockDuration: string;
/**
* Specifies the maximum queue size in megabytes. Any attempt to enqueue a message that
* will cause the queue to exceed this value will fail.
*/
maxSizeInMegabytes: number;
/**
* If enabled, the topic will detect duplicate messages within the time
* span specified by the DuplicateDetectionHistoryTimeWindow property.
* Settable only at queue creation time.
*/
readonly requiresDuplicateDetection: boolean;
/**
* If set to true, the queue will be session-aware and only SessionReceiver
* will be supported. Session-aware queues are not supported through REST.
* Settable only at queue creation time.
*/
readonly requiresSession: boolean;
/**
* Depending on whether DeadLettering is enabled, a message is automatically
* moved to the dead-letter sub-queue or deleted if it has been stored in the
* queue for longer than the specified time.
* This value is overwritten by a TTL specified on the message
* if and only if the message TTL is smaller than the TTL set on the queue.
* This value is immutable after the Queue has been created.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
defaultMessageTimeToLive: string;
/**
* If it is enabled and a message expires, the Service Bus moves the message
* from the queue into the queue’s dead-letter sub-queue. If disabled,
* message will be permanently deleted from the queue.
* Settable only at queue creation time.
*/
deadLetteringOnMessageExpiration: boolean;
/**
* Specifies the time span during which the Service Bus detects message duplication.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
duplicateDetectionHistoryTimeWindow: string;
/**
* The maximum delivery count of messages after which if it is still not settled,
* gets moved to the dead-letter sub-queue.
*/
maxDeliveryCount: number;
/**
* Specifies if batched operations should be allowed.
*/
enableBatchedOperations: boolean;
/**
* Authorization rules on the queue
*/
authorizationRules?: AuthorizationRule[];
/**
* Status of the messaging entity.
*/
status: EntityStatus;
/**
* Absolute URL or the name of the queue or topic the
* messages are to be forwarded to.
* For example, an absolute URL input would be of the form
* `sb://<your-service-bus-namespace-endpoint>/<queue-or-topic-name>`
*/
forwardTo?: string;
/**
* The user provided metadata information associated with the queue.
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
userMetadata: string;
/**
* Max idle time before entity is deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
autoDeleteOnIdle: string;
/**
* Specifies whether the queue should be partitioned.
*/
readonly enablePartitioning: boolean;
/**
* Absolute URL or the name of the queue or topic the dead-lettered
* messages are to be forwarded to.
* For example, an absolute URL input would be of the form
* `sb://<your-service-bus-namespace-endpoint>/<queue-or-topic-name>`
*/
forwardDeadLetteredMessagesTo?: string;
/**
* Specifies whether express entities are enabled on queue.
*/
readonly enableExpress: boolean;
}
/**
* @internal
* @ignore
* Internal representation of settable options on a queue
*/
export interface InternalQueueOptions {
/**
* Determines the amount of time in seconds in which a message should be locked for
* processing by a receiver. After this period, the message is unlocked and
* can be consumed by the next receiver.
* Settable only at queue creation time.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
LockDuration?: string;
/**
* The max size in MegaBytes
*
*/
MaxSizeInMegabytes?: string;
/**
* If enabled, the topic will detect duplicate messages within the time
* span specified by the DuplicateDetectionHistoryTimeWindow property.
* Settable only at queue creation time.
*/
RequiresDuplicateDetection?: string;
/**
* If set to true, the queue will be session-aware and only SessionReceiver
* will be supported. Session-aware queues are not supported through REST.
* Settable only at queue creation time.
*/
RequiresSession?: string;
/**
* Depending on whether DeadLettering is enabled, a message is automatically moved to
* the DeadLetterQueue or deleted if it has been stored in the queue for longer than
* the specified time. This value is overwritten by a TTL specified on the message
* if and only if the message TTL is smaller than the TTL set on the queue.
* This value is immutable after the Queue has been created.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
DefaultMessageTimeToLive?: string;
/**
* If it is enabled and a message expires, the Service Bus moves the message
* from the queue into the queue’s dead-letter sub-queue. If disabled,
* message will be permanently deleted from the queue.
* Settable only at queue creation time.
*/
DeadLetteringOnMessageExpiration?: string;
/**
* Specifies the time span during which the Service Bus detects message duplication.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
DuplicateDetectionHistoryTimeWindow?: string;
/**
* The maximum delivery count of messages after which if it is still not settled,
* gets moved to the dead-letter sub-queue.
*
*/
MaxDeliveryCount?: string;
/**
* Specifies if batched operations should be allowed.
*/
EnableBatchedOperations?: string;
/**
* Authorization rules on the queue
*/
AuthorizationRules?: any;
/**
* Status of the messaging entity.
*/
Status?: string;
/**
* Absolute URL or the name of the queue or topic the
* messages are to be forwarded to.
* For example, an absolute URL input would be of the form
* `sb://<your-service-bus-namespace-endpoint>/<queue-or-topic-name>`
*/
ForwardTo?: string;
/**
* The user provided metadata information associated with the queue.
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
UserMetadata?: string;
/**
* Max idle time before entity is deleted.
* This is to be specified in ISO-8601 duration format
* such as "PT1M" for 1 minute, "PT5S" for 5 seconds.
*
* More on ISO-8601 duration format: https://en.wikipedia.org/wiki/ISO_8601#Durations
*/
AutoDeleteOnIdle?: string;
/**
* Specifies whether the queue should be partitioned.
*/
EnablePartitioning?: string;
/**
* Absolute URL or the name of the queue or topic the dead-lettered
* messages are to be forwarded to.
* For example, an absolute URL input would be of the form
* `sb://<your-service-bus-namespace-endpoint>/<queue-or-topic-name>`
*/
ForwardDeadLetteredMessagesTo?: string;
/**
* Specifies whether express entities are enabled on queue.
*/
EnableExpress?: string;
}
/**
* Represents runtime info attributes of a queue entity
*/
export interface QueueRuntimeProperties {
/**
* Name of the queue
*/
name: string;
/**
* Created at timestamp
*/
createdAt: Date;
/**
* Updated at timestamp
*/
modifiedAt: Date;
/**
* Accessed at timestamp
*/
accessedAt: Date;
/**
* The entity's message count.
*
*/
totalMessageCount?: number;
/**
* The number of active messages in the queue.
*/
activeMessageCount: number;
/**
* The number of messages that have been dead lettered.
*/
deadLetterMessageCount: number;
/**
* The number of scheduled messages.
*/
scheduledMessageCount: number;
/**
* The number of messages transferred to another queue, topic, or subscription
*/
transferMessageCount: number;
/**
* The number of messages transferred to the dead letter queue.
*/
transferDeadLetterMessageCount: number;
/**
* The entity's size in bytes.
*
*/
sizeInBytes?: number;
}
/**
* @internal
* @ignore
* Atom XML Serializer for Queues.
*/
export class QueueResourceSerializer implements AtomXmlSerializer {
serialize(resource: InternalQueueOptions): object {
return serializeToAtomXmlRequest("QueueDescription", resource);
}
async deserialize(response: HttpOperationResponse): Promise<HttpOperationResponse> {
return deserializeAtomXmlResponse(["QueueName"], response);
}
}