| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.ServiceBus.Management |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using Microsoft.Azure.ServiceBus.Primitives; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Represents the metadata description of the queue. |
| | 12 | | /// </summary> |
| | 13 | | public class QueueDescription : IEquatable<QueueDescription> |
| | 14 | | { |
| 30 | 15 | | internal TimeSpan duplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1); |
| | 16 | | internal string path; |
| 30 | 17 | | TimeSpan lockDuration = TimeSpan.FromSeconds(60); |
| 30 | 18 | | TimeSpan defaultMessageTimeToLive = TimeSpan.MaxValue; |
| 30 | 19 | | TimeSpan autoDeleteOnIdle = TimeSpan.MaxValue; |
| 30 | 20 | | int maxDeliveryCount = 10; |
| | 21 | | string forwardTo = null; |
| | 22 | | string forwardDeadLetteredMessagesTo = null; |
| | 23 | | string userMetadata = null; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Initializes a new instance of QueueDescription class with the specified relative path. |
| | 27 | | /// </summary> |
| | 28 | | /// <param name="path">Path of the queue relative to the namespace base address.</param> |
| 30 | 29 | | public QueueDescription(string path) |
| | 30 | | { |
| 30 | 31 | | this.Path = path; |
| 30 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Path of the queue relative to the namespace base address. |
| | 36 | | /// </summary> |
| | 37 | | /// <remarks>Max length is 260 chars. Cannot start or end with a slash. |
| | 38 | | /// Cannot have restricted characters: '@','?','#','*'</remarks> |
| | 39 | | public string Path |
| | 40 | | { |
| 6 | 41 | | get => this.path; |
| | 42 | | set |
| | 43 | | { |
| 40 | 44 | | EntityNameHelper.CheckValidQueueName(value, nameof(Path)); |
| 36 | 45 | | this.path = value; |
| 36 | 46 | | } |
| | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Duration of a peek lock receive. i.e., the amount of time that the message is locked by a given receiver so |
| | 51 | | /// no other receiver receives the same message. |
| | 52 | | /// </summary> |
| | 53 | | /// <remarks>Max value is 5 minutes. Default value is 60 seconds.</remarks> |
| | 54 | | public TimeSpan LockDuration |
| | 55 | | { |
| 0 | 56 | | get => this.lockDuration; |
| | 57 | | set |
| | 58 | | { |
| 0 | 59 | | TimeoutHelper.ThrowIfNonPositiveArgument(value, nameof(LockDuration)); |
| 0 | 60 | | this.lockDuration = value; |
| 0 | 61 | | } |
| | 62 | | } |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// The maximum size of the queue in megabytes, which is the size of memory allocated for the queue. |
| | 66 | | /// </summary> |
| | 67 | | /// <remarks>Default value is 1024.</remarks> |
| 0 | 68 | | public long MaxSizeInMB { get; set; } = 1024; |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// This value indicates if the queue requires guard against duplicate messages. If true, duplicate messages hav |
| | 72 | | /// <see cref="Message.MessageId"/> and sent to queue within duration of <see cref="DuplicateDetectionHistoryTim |
| | 73 | | /// will be discarded. |
| | 74 | | /// </summary> |
| | 75 | | /// <remarks>Defaults to false.</remarks> |
| 0 | 76 | | public bool RequiresDuplicateDetection { get; set; } = false; |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// This indicates whether the queue supports the concept of session. Sessionful-messages follow FIFO ordering. |
| | 80 | | /// </summary> |
| | 81 | | /// <remarks> |
| | 82 | | /// If true, the receiver can only receive messages using <see cref="SessionClient.AcceptMessageSessionAsync()"/ |
| | 83 | | /// Defaults to false. |
| | 84 | | /// </remarks> |
| 0 | 85 | | public bool RequiresSession { get; set; } = false; |
| | 86 | |
|
| | 87 | | /// <summary> |
| | 88 | | /// The default time to live value for the messages. This is the duration after which the message expires, start |
| | 89 | | /// the message is sent to Service Bus. </summary> |
| | 90 | | /// <remarks> |
| | 91 | | /// This is the default value used when <see cref="Message.TimeToLive"/> is not set on a |
| | 92 | | /// message itself. Messages older than their TimeToLive value will expire and no longer be retained in the mes |
| | 93 | | /// Subscribers will be unable to receive expired messages. |
| | 94 | | /// Default value is <see cref="TimeSpan.MaxValue"/>. |
| | 95 | | /// </remarks> |
| | 96 | | public TimeSpan DefaultMessageTimeToLive |
| | 97 | | { |
| 0 | 98 | | get => this.defaultMessageTimeToLive; |
| | 99 | | set |
| | 100 | | { |
| 0 | 101 | | if (value < ManagementClientConstants.MinimumAllowedTimeToLive || value > ManagementClientConstants.Maxi |
| | 102 | | { |
| 0 | 103 | | throw new ArgumentOutOfRangeException(nameof(DefaultMessageTimeToLive), |
| 0 | 104 | | $"The value must be between {ManagementClientConstants.MinimumAllowedTimeToLive} and {Management |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | this.defaultMessageTimeToLive = value; |
| 0 | 108 | | } |
| | 109 | | } |
| | 110 | |
|
| | 111 | | /// <summary> |
| | 112 | | /// The <see cref="TimeSpan"/> idle interval after which the queue is automatically deleted. |
| | 113 | | /// </summary> |
| | 114 | | /// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks> |
| | 115 | | public TimeSpan AutoDeleteOnIdle |
| | 116 | | { |
| 0 | 117 | | get => this.autoDeleteOnIdle; |
| | 118 | | set |
| | 119 | | { |
| 0 | 120 | | if (value < ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle) |
| | 121 | | { |
| 0 | 122 | | throw new ArgumentOutOfRangeException(nameof(AutoDeleteOnIdle), |
| 0 | 123 | | $"The value must be greater than {ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle}"); |
| | 124 | | } |
| | 125 | |
|
| 0 | 126 | | this.autoDeleteOnIdle = value; |
| 0 | 127 | | } |
| | 128 | | } |
| | 129 | |
|
| | 130 | | /// <summary> |
| | 131 | | /// Indicates whether this queue has dead letter support when a message expires. |
| | 132 | | /// </summary> |
| | 133 | | /// <remarks>If true, the expired messages are moved to dead-letter sub-queue. Default value is false.</remarks> |
| 0 | 134 | | public bool EnableDeadLetteringOnMessageExpiration { get; set; } = false; |
| | 135 | |
|
| | 136 | | /// <summary> |
| | 137 | | /// The <see cref="TimeSpan"/> duration of duplicate detection history that is maintained by the service. |
| | 138 | | /// </summary> |
| | 139 | | /// <remarks> |
| | 140 | | /// The default value is 1 minute. Max value is 7 days and minimum is 20 seconds. |
| | 141 | | /// </remarks> |
| | 142 | | public TimeSpan DuplicateDetectionHistoryTimeWindow |
| | 143 | | { |
| 0 | 144 | | get => this.duplicateDetectionHistoryTimeWindow; |
| | 145 | | set |
| | 146 | | { |
| 0 | 147 | | if (value < ManagementClientConstants.MinimumDuplicateDetectionHistoryTimeWindow || value > ManagementCl |
| | 148 | | { |
| 0 | 149 | | throw new ArgumentOutOfRangeException(nameof(DuplicateDetectionHistoryTimeWindow), |
| 0 | 150 | | $"The value must be between {ManagementClientConstants.MinimumDuplicateDetectionHistoryTimeWindo |
| | 151 | | } |
| | 152 | |
|
| 0 | 153 | | this.duplicateDetectionHistoryTimeWindow = value; |
| 0 | 154 | | } |
| | 155 | | } |
| | 156 | |
|
| | 157 | | /// <summary> |
| | 158 | | /// The maximum delivery count of a message before it is dead-lettered. |
| | 159 | | /// </summary> |
| | 160 | | /// <remarks>The delivery count is increased when a message is received in <see cref="ReceiveMode.PeekLock"/> mo |
| | 161 | | /// and didn't complete the message before the message lock expired. |
| | 162 | | /// Default value is 10. Minimum value is 1.</remarks> |
| | 163 | | public int MaxDeliveryCount |
| | 164 | | { |
| 0 | 165 | | get => this.maxDeliveryCount; |
| | 166 | | set |
| | 167 | | { |
| 0 | 168 | | if (value < ManagementClientConstants.MinAllowedMaxDeliveryCount) |
| | 169 | | { |
| 0 | 170 | | throw new ArgumentOutOfRangeException(nameof(MaxDeliveryCount), |
| 0 | 171 | | $"The value must be greater than {ManagementClientConstants.MinAllowedMaxDeliveryCount}"); |
| | 172 | | } |
| | 173 | |
|
| 0 | 174 | | this.maxDeliveryCount = value; |
| 0 | 175 | | } |
| | 176 | | } |
| | 177 | |
|
| | 178 | | /// <summary> |
| | 179 | | /// Indicates whether server-side batched operations are enabled. |
| | 180 | | /// </summary> |
| | 181 | | /// <remarks>Defaults to true.</remarks> |
| 0 | 182 | | public bool EnableBatchedOperations { get; set; } = true; |
| | 183 | |
|
| | 184 | | /// <summary> |
| | 185 | | /// The <see cref="AuthorizationRules"/> on the queue to control user access at entity level. |
| | 186 | | /// </summary> |
| 0 | 187 | | public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules(); |
| | 188 | |
|
| | 189 | | /// <summary> |
| | 190 | | /// The current status of the queue (Enabled / Disabled). |
| | 191 | | /// </summary> |
| | 192 | | /// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks> |
| 0 | 193 | | public EntityStatus Status { get; set; } = EntityStatus.Active; |
| | 194 | |
|
| | 195 | | /// <summary> |
| | 196 | | /// The path of the recipient entity to which all the messages sent to the queue are forwarded to. |
| | 197 | | /// </summary> |
| | 198 | | /// <remarks>If set, user cannot manually receive messages from this queue. The destination entity |
| | 199 | | /// must be an already existing entity.</remarks> |
| | 200 | | public string ForwardTo |
| | 201 | | { |
| 6 | 202 | | get => this.forwardTo; |
| | 203 | | set |
| | 204 | | { |
| 10 | 205 | | if (string.IsNullOrWhiteSpace(value)) |
| | 206 | | { |
| 0 | 207 | | this.forwardTo = value; |
| 0 | 208 | | return; |
| | 209 | | } |
| | 210 | |
|
| 10 | 211 | | EntityNameHelper.CheckValidQueueName(value, nameof(ForwardTo)); |
| 6 | 212 | | if (this.path.Equals(value, StringComparison.CurrentCultureIgnoreCase)) |
| | 213 | | { |
| 0 | 214 | | throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself"); |
| | 215 | | } |
| | 216 | |
|
| 6 | 217 | | this.forwardTo = value; |
| 6 | 218 | | } |
| | 219 | | } |
| | 220 | |
|
| | 221 | | /// <summary> |
| | 222 | | /// The path of the recipient entity to which all the dead-lettered messages of this queue are forwarded to. |
| | 223 | | /// </summary> |
| | 224 | | /// <remarks>If set, user cannot manually receive dead-lettered messages from this queue. The destination |
| | 225 | | /// entity must already exist.</remarks> |
| | 226 | | public string ForwardDeadLetteredMessagesTo |
| | 227 | | { |
| 6 | 228 | | get => this.forwardDeadLetteredMessagesTo; |
| | 229 | | set |
| | 230 | | { |
| 10 | 231 | | if (string.IsNullOrWhiteSpace(value)) |
| | 232 | | { |
| 0 | 233 | | this.forwardDeadLetteredMessagesTo = value; |
| 0 | 234 | | return; |
| | 235 | | } |
| | 236 | |
|
| 10 | 237 | | EntityNameHelper.CheckValidQueueName(value, nameof(ForwardDeadLetteredMessagesTo)); |
| 6 | 238 | | if (this.path.Equals(value, StringComparison.CurrentCultureIgnoreCase)) |
| | 239 | | { |
| 0 | 240 | | throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself"); |
| | 241 | | } |
| | 242 | |
|
| 6 | 243 | | this.forwardDeadLetteredMessagesTo = value; |
| 6 | 244 | | } |
| | 245 | | } |
| | 246 | |
|
| | 247 | | /// <summary> |
| | 248 | | /// Indicates whether the queue is to be partitioned across multiple message brokers. |
| | 249 | | /// </summary> |
| | 250 | | /// <remarks>Defaults to false.</remarks> |
| 0 | 251 | | public bool EnablePartitioning { get; set; } = false; |
| | 252 | |
|
| | 253 | | /// <summary> |
| | 254 | | /// Custom metdata that user can associate with the description. |
| | 255 | | /// </summary> |
| | 256 | | /// <remarks>Cannot be null. Max length is 1024 chars.</remarks> |
| | 257 | | public string UserMetadata |
| | 258 | | { |
| 0 | 259 | | get => this.userMetadata; |
| | 260 | | set |
| | 261 | | { |
| 0 | 262 | | if (value == null) |
| | 263 | | { |
| 0 | 264 | | throw new ArgumentNullException(nameof(UserMetadata), $"Value cannot be null"); |
| | 265 | | } |
| | 266 | |
|
| 0 | 267 | | if (value.Length > ManagementClientConstants.MaxUserMetadataLength) |
| | 268 | | { |
| 0 | 269 | | throw new ArgumentOutOfRangeException(nameof(UserMetadata), $"Length cannot cross {ManagementClientC |
| | 270 | | } |
| | 271 | |
|
| 0 | 272 | | this.userMetadata = value; |
| 0 | 273 | | } |
| | 274 | | } |
| | 275 | |
|
| | 276 | | /// <summary> |
| | 277 | | /// List of properties that were retrieved using GetQueue but are not understood by this version of client is st |
| | 278 | | /// The list will be sent back when an already retrieved QueueDescription will be used in UpdateQueue call. |
| | 279 | | /// </summary> |
| 0 | 280 | | internal List<object> UnknownProperties { get; set; } |
| | 281 | |
|
| | 282 | | public override int GetHashCode() |
| | 283 | | { |
| 0 | 284 | | return this.Path?.GetHashCode() ?? base.GetHashCode(); |
| | 285 | | } |
| | 286 | |
|
| | 287 | | public override bool Equals(object obj) |
| | 288 | | { |
| 0 | 289 | | var other = obj as QueueDescription; |
| 0 | 290 | | return this.Equals(other); |
| | 291 | | } |
| | 292 | |
|
| | 293 | | public bool Equals(QueueDescription otherDescription) |
| | 294 | | { |
| 0 | 295 | | if (otherDescription is QueueDescription other |
| 0 | 296 | | && this.Path.Equals(other.Path, StringComparison.OrdinalIgnoreCase) |
| 0 | 297 | | && this.AutoDeleteOnIdle.Equals(other.AutoDeleteOnIdle) |
| 0 | 298 | | && this.DefaultMessageTimeToLive.Equals(other.DefaultMessageTimeToLive) |
| 0 | 299 | | && (!this.RequiresDuplicateDetection || this.DuplicateDetectionHistoryTimeWindow.Equals(other.DuplicateD |
| 0 | 300 | | && this.EnableBatchedOperations == other.EnableBatchedOperations |
| 0 | 301 | | && this.EnableDeadLetteringOnMessageExpiration == other.EnableDeadLetteringOnMessageExpiration |
| 0 | 302 | | && this.EnablePartitioning == other.EnablePartitioning |
| 0 | 303 | | && string.Equals(this.ForwardDeadLetteredMessagesTo, other.ForwardDeadLetteredMessagesTo, StringComparis |
| 0 | 304 | | && string.Equals(this.ForwardTo, other.ForwardTo, StringComparison.OrdinalIgnoreCase) |
| 0 | 305 | | && this.LockDuration.Equals(other.LockDuration) |
| 0 | 306 | | && this.MaxDeliveryCount == other.MaxDeliveryCount |
| 0 | 307 | | && this.MaxSizeInMB == other.MaxSizeInMB |
| 0 | 308 | | && this.RequiresDuplicateDetection.Equals(other.RequiresDuplicateDetection) |
| 0 | 309 | | && this.RequiresSession.Equals(other.RequiresSession) |
| 0 | 310 | | && this.Status.Equals(other.Status) |
| 0 | 311 | | && string.Equals(this.userMetadata, other.userMetadata, StringComparison.OrdinalIgnoreCase) |
| 0 | 312 | | && (this.AuthorizationRules != null && other.AuthorizationRules != null |
| 0 | 313 | | || this.AuthorizationRules == null && other.AuthorizationRules == null) |
| 0 | 314 | | && (this.AuthorizationRules == null || this.AuthorizationRules.Equals(other.AuthorizationRules))) |
| | 315 | | { |
| 0 | 316 | | return true; |
| | 317 | | } |
| | 318 | |
|
| 0 | 319 | | return false; |
| | 320 | | } |
| | 321 | |
|
| | 322 | | public static bool operator ==(QueueDescription o1, QueueDescription o2) |
| | 323 | | { |
| 0 | 324 | | if (ReferenceEquals(o1, o2)) |
| | 325 | | { |
| 0 | 326 | | return true; |
| | 327 | | } |
| | 328 | |
|
| 0 | 329 | | if (ReferenceEquals(o1, null) || ReferenceEquals(o2, null)) |
| | 330 | | { |
| 0 | 331 | | return false; |
| | 332 | | } |
| | 333 | |
|
| 0 | 334 | | return o1.Equals(o2); |
| | 335 | | } |
| | 336 | |
|
| | 337 | | public static bool operator !=(QueueDescription o1, QueueDescription o2) |
| | 338 | | { |
| 0 | 339 | | return !(o1 == o2); |
| | 340 | | } |
| | 341 | | } |
| | 342 | | } |