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