| | 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 topic. |
| | 12 | | /// </summary> |
| | 13 | | public class TopicProperties : IEquatable<TopicProperties> |
| | 14 | | { |
| 108 | 15 | | private TimeSpan _duplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1); |
| | 16 | | private string _name; |
| 108 | 17 | | private TimeSpan _defaultMessageTimeToLive = TimeSpan.MaxValue; |
| 108 | 18 | | private TimeSpan _autoDeleteOnIdle = TimeSpan.MaxValue; |
| | 19 | | private string _userMetadata = null; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Initializes a new instance of TopicDescription class with the specified relative name. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="name">Name of the topic relative to the namespace base address.</param> |
| 68 | 25 | | internal TopicProperties(string name) |
| | 26 | | { |
| 68 | 27 | | Name = name; |
| 68 | 28 | | } |
| | 29 | |
|
| 40 | 30 | | internal TopicProperties(CreateTopicOptions options) |
| | 31 | | { |
| 40 | 32 | | Name = options.Name; |
| 40 | 33 | | MaxSizeInMegabytes = options.MaxSizeInMegabytes; |
| 40 | 34 | | RequiresDuplicateDetection = options.RequiresDuplicateDetection; |
| 40 | 35 | | DefaultMessageTimeToLive = options.DefaultMessageTimeToLive; |
| 40 | 36 | | AutoDeleteOnIdle = options.AutoDeleteOnIdle; |
| 40 | 37 | | DuplicateDetectionHistoryTimeWindow = options.DuplicateDetectionHistoryTimeWindow; |
| 40 | 38 | | EnableBatchedOperations = options.EnableBatchedOperations; |
| 40 | 39 | | AuthorizationRules = options.AuthorizationRules; |
| 40 | 40 | | Status = options.Status; |
| 40 | 41 | | EnableBatchedOperations = options.EnableBatchedOperations; |
| 40 | 42 | | if (options.UserMetadata != null) |
| | 43 | | { |
| 4 | 44 | | UserMetadata = options.UserMetadata; |
| | 45 | | } |
| 40 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// The default time to live value for the messages. This is the duration after which the message expires, start |
| | 50 | | /// the message is sent to Service Bus. </summary> |
| | 51 | | /// <remarks> |
| | 52 | | /// This is the default value used when <see cref="ServiceBusMessage.TimeToLive"/> is not set on a |
| | 53 | | /// message itself. Messages older than their TimeToLive value will expire and no longer be retained in the mes |
| | 54 | | /// Subscribers will be unable to receive expired messages. |
| | 55 | | /// Default value is <see cref="TimeSpan.MaxValue"/>. |
| | 56 | | /// </remarks> |
| | 57 | | public TimeSpan DefaultMessageTimeToLive |
| | 58 | | { |
| 84 | 59 | | get => _defaultMessageTimeToLive; |
| | 60 | | set |
| | 61 | | { |
| 100 | 62 | | Argument.AssertInRange( |
| 100 | 63 | | value, |
| 100 | 64 | | ManagementClientConstants.MinimumAllowedTimeToLive, |
| 100 | 65 | | ManagementClientConstants.MaximumAllowedTimeToLive, |
| 100 | 66 | | nameof(DefaultMessageTimeToLive)); |
| | 67 | |
|
| 100 | 68 | | _defaultMessageTimeToLive = value; |
| 100 | 69 | | } |
| | 70 | | } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// The <see cref="TimeSpan"/> idle interval after which the topic is automatically deleted. |
| | 74 | | /// </summary> |
| | 75 | | /// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks> |
| | 76 | | public TimeSpan AutoDeleteOnIdle |
| | 77 | | { |
| 88 | 78 | | get => _autoDeleteOnIdle; |
| | 79 | | set |
| | 80 | | { |
| 104 | 81 | | Argument.AssertAtLeast( |
| 104 | 82 | | value, |
| 104 | 83 | | ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle, |
| 104 | 84 | | nameof(AutoDeleteOnIdle)); |
| | 85 | |
|
| 104 | 86 | | _autoDeleteOnIdle = value; |
| 104 | 87 | | } |
| | 88 | | } |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// The maximum size of the topic in megabytes, which is the size of memory allocated for the topic. |
| | 92 | | /// </summary> |
| | 93 | | /// <remarks>Default value is 1024.</remarks> |
| 288 | 94 | | public long MaxSizeInMegabytes { get; set; } = 1024; |
| | 95 | |
|
| | 96 | | /// <summary> |
| | 97 | | /// This value indicates if the topic requires guard against duplicate messages. If true, duplicate messages hav |
| | 98 | | /// <see cref="ServiceBusMessage.MessageId"/> and sent to topic within duration of <see cref="DuplicateDetection |
| | 99 | | /// will be discarded. |
| | 100 | | /// </summary> |
| | 101 | | /// <remarks>Defaults to false.</remarks> |
| 236 | 102 | | public bool RequiresDuplicateDetection { get; set; } = false; |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// The <see cref="TimeSpan"/> duration of duplicate detection history that is maintained by the service. |
| | 106 | | /// </summary> |
| | 107 | | /// <remarks> |
| | 108 | | /// The default value is 1 minute. Max value is 7 days and minimum is 20 seconds. |
| | 109 | | /// </remarks> |
| | 110 | | public TimeSpan DuplicateDetectionHistoryTimeWindow |
| | 111 | | { |
| 40 | 112 | | get => _duplicateDetectionHistoryTimeWindow; |
| | 113 | | set |
| | 114 | | { |
| 100 | 115 | | Argument.AssertInRange( |
| 100 | 116 | | value, |
| 100 | 117 | | ManagementClientConstants.MinimumDuplicateDetectionHistoryTimeWindow, |
| 100 | 118 | | ManagementClientConstants.MaximumDuplicateDetectionHistoryTimeWindow, |
| 100 | 119 | | nameof(DuplicateDetectionHistoryTimeWindow)); |
| | 120 | |
|
| 100 | 121 | | _duplicateDetectionHistoryTimeWindow = value; |
| 100 | 122 | | } |
| | 123 | | } |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Name of the topic relative to the namespace base address. |
| | 127 | | /// </summary> |
| | 128 | | /// <remarks>Max length is 260 chars. Cannot start or end with a slash. |
| | 129 | | /// Cannot have restricted characters: '@','?','#','*'</remarks> |
| | 130 | | public string Name |
| | 131 | | { |
| 88 | 132 | | get => _name; |
| | 133 | | set |
| | 134 | | { |
| 108 | 135 | | EntityNameFormatter.CheckValidTopicName(value, nameof(Name)); |
| 108 | 136 | | _name = value; |
| 108 | 137 | | } |
| | 138 | | } |
| | 139 | |
|
| | 140 | | /// <summary> |
| | 141 | | /// The <see cref="AuthorizationRules"/> on the topic to control user access at entity level. |
| | 142 | | /// </summary> |
| 308 | 143 | | public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules(); |
| | 144 | |
|
| | 145 | | /// <summary> |
| | 146 | | /// The current status of the topic (Enabled / Disabled). |
| | 147 | | /// </summary> |
| | 148 | | /// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks> |
| 284 | 149 | | public EntityStatus Status { get; set; } = EntityStatus.Active; |
| | 150 | |
|
| | 151 | | /// <summary> |
| | 152 | | /// Indicates whether the topic is to be partitioned across multiple message brokers. |
| | 153 | | /// </summary> |
| | 154 | | /// <remarks>Defaults to false.</remarks> |
| 136 | 155 | | public bool EnablePartitioning { get; set; } = false; |
| | 156 | |
|
| | 157 | | /// <summary> |
| | 158 | | /// Defines whether ordering needs to be maintained. If true, messages sent to topic will be |
| | 159 | | /// forwarded to the subscription in order. |
| | 160 | | /// </summary> |
| | 161 | | /// <remarks>Defaults to false.</remarks> |
| 112 | 162 | | public bool SupportOrdering { get; set; } = false; |
| | 163 | |
|
| | 164 | | /// <summary> |
| | 165 | | /// Indicates whether server-side batched operations are enabled. |
| | 166 | | /// </summary> |
| | 167 | | /// <remarks>Defaults to true.</remarks> |
| 332 | 168 | | public bool EnableBatchedOperations { get; set; } = true; |
| | 169 | |
|
| | 170 | | /// <summary> |
| | 171 | | /// Custom metdata that user can associate with the description. |
| | 172 | | /// </summary> |
| | 173 | | /// <remarks>Cannot be null. Max length is 1024 chars.</remarks> |
| | 174 | | public string UserMetadata |
| | 175 | | { |
| 72 | 176 | | get => _userMetadata; |
| | 177 | | set |
| | 178 | | { |
| 24 | 179 | | Argument.AssertNotNull(value, nameof(UserMetadata)); |
| 24 | 180 | | Argument.AssertNotTooLong( |
| 24 | 181 | | value, |
| 24 | 182 | | ManagementClientConstants.MaxUserMetadataLength, |
| 24 | 183 | | nameof(UserMetadata)); |
| | 184 | |
|
| 24 | 185 | | _userMetadata = value; |
| 24 | 186 | | } |
| | 187 | | } |
| | 188 | |
|
| | 189 | | /// <summary> |
| | 190 | | /// List of properties that were retrieved using GetTopic but are not understood by this version of client is st |
| | 191 | | /// The list will be sent back when an already retrieved TopicDescription will be used in UpdateTopic call. |
| | 192 | | /// </summary> |
| 752 | 193 | | internal List<object> UnknownProperties { get; set; } |
| | 194 | |
|
| | 195 | | /// <summary> |
| | 196 | | /// Returns a hash code for this instance. |
| | 197 | | /// </summary> |
| | 198 | | public override int GetHashCode() |
| | 199 | | { |
| 0 | 200 | | return Name?.GetHashCode() ?? base.GetHashCode(); |
| | 201 | | } |
| | 202 | |
|
| | 203 | | /// <summary>Determines whether the specified object is equal to the current object.</summary> |
| | 204 | | public override bool Equals(object obj) |
| | 205 | | { |
| 0 | 206 | | var other = obj as TopicProperties; |
| 0 | 207 | | return Equals(other); |
| | 208 | | } |
| | 209 | |
|
| | 210 | | /// <summary>Determines whether the specified object is equal to the current object.</summary> |
| | 211 | | public bool Equals(TopicProperties other) |
| | 212 | | { |
| 8 | 213 | | if (other is TopicProperties otherDescription |
| 8 | 214 | | && Name.Equals(otherDescription.Name, StringComparison.OrdinalIgnoreCase) |
| 8 | 215 | | && AutoDeleteOnIdle.Equals(otherDescription.AutoDeleteOnIdle) |
| 8 | 216 | | && DefaultMessageTimeToLive.Equals(otherDescription.DefaultMessageTimeToLive) |
| 8 | 217 | | && (!RequiresDuplicateDetection || DuplicateDetectionHistoryTimeWindow.Equals(otherDescription.Duplicate |
| 8 | 218 | | && EnableBatchedOperations == otherDescription.EnableBatchedOperations |
| 8 | 219 | | && EnablePartitioning == otherDescription.EnablePartitioning |
| 8 | 220 | | && MaxSizeInMegabytes == otherDescription.MaxSizeInMegabytes |
| 8 | 221 | | && RequiresDuplicateDetection.Equals(otherDescription.RequiresDuplicateDetection) |
| 8 | 222 | | && Status.Equals(otherDescription.Status) |
| 8 | 223 | | && string.Equals(_userMetadata, otherDescription._userMetadata, StringComparison.OrdinalIgnoreCase) |
| 8 | 224 | | && (AuthorizationRules != null && otherDescription.AuthorizationRules != null |
| 8 | 225 | | || AuthorizationRules == null && otherDescription.AuthorizationRules == null) |
| 8 | 226 | | && (AuthorizationRules == null || AuthorizationRules.Equals(otherDescription.AuthorizationRules))) |
| | 227 | | { |
| 8 | 228 | | return true; |
| | 229 | | } |
| | 230 | |
|
| 0 | 231 | | return false; |
| | 232 | | } |
| | 233 | |
|
| | 234 | | /// <summary></summary> |
| | 235 | | public static bool operator ==(TopicProperties left, TopicProperties right) |
| | 236 | | { |
| 0 | 237 | | if (ReferenceEquals(left, right)) |
| | 238 | | { |
| 0 | 239 | | return true; |
| | 240 | | } |
| | 241 | |
|
| 0 | 242 | | if (ReferenceEquals(left, null) || ReferenceEquals(right, null)) |
| | 243 | | { |
| 0 | 244 | | return false; |
| | 245 | | } |
| | 246 | |
|
| 0 | 247 | | return left.Equals(right); |
| | 248 | | } |
| | 249 | |
|
| | 250 | | /// <summary></summary> |
| | 251 | | public static bool operator !=(TopicProperties left, TopicProperties right) |
| | 252 | | { |
| 0 | 253 | | return !(left == right); |
| | 254 | | } |
| | 255 | | } |
| | 256 | | } |