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