-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
CreateTopicOptions.cs
268 lines (239 loc) · 11.1 KB
/
CreateTopicOptions.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Azure.Core;
namespace Azure.Messaging.ServiceBus.Administration
{
/// <summary>
/// Represents the options that can be specified for the creation of a topic.
/// </summary>
public class CreateTopicOptions : IEquatable<CreateTopicOptions>
{
private TimeSpan _duplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1);
private string _name;
private TimeSpan _defaultMessageTimeToLive = TimeSpan.MaxValue;
private TimeSpan _autoDeleteOnIdle = TimeSpan.MaxValue;
private string _userMetadata;
/// <summary>
/// Initializes a new instance of <see cref="CreateTopicOptions"/> with the specified relative name.
/// </summary>
/// <param name="name">Name of the topic relative to the namespace base address.</param>
public CreateTopicOptions(string name)
{
Name = name;
}
/// <summary>
/// Initializes a new instance of <see cref="CreateTopicOptions"/> based on the
/// specified <see cref="TopicProperties"/> instance. This is useful for creating a new topic based
/// on the properties of an existing topic.
/// </summary>
/// <param name="topic">Existing topic to create options from.</param>
public CreateTopicOptions(TopicProperties topic)
{
Name = topic.Name;
MaxSizeInMegabytes = topic.MaxSizeInMegabytes;
RequiresDuplicateDetection = topic.RequiresDuplicateDetection;
DefaultMessageTimeToLive = topic.DefaultMessageTimeToLive;
AutoDeleteOnIdle = topic.AutoDeleteOnIdle;
DuplicateDetectionHistoryTimeWindow = topic.DuplicateDetectionHistoryTimeWindow;
EnableBatchedOperations = topic.EnableBatchedOperations;
AuthorizationRules = topic.AuthorizationRules.Clone();
Status = topic.Status;
EnablePartitioning = topic.EnablePartitioning;
MaxMessageSizeInKilobytes = topic.MaxMessageSizeInKilobytes;
SupportOrdering = topic.SupportOrdering;
if (topic.UserMetadata != null)
{
UserMetadata = topic.UserMetadata;
}
}
/// <summary>
/// The default time to live value for the messages. This is the duration after which the message expires,
/// starting from when the message is sent to Service Bus. </summary>
/// <remarks>
/// This is the default value used when <see cref="ServiceBusMessage.TimeToLive"/> is not set on a
/// message itself. Messages older than their TimeToLive value will expire and no longer be retained
/// in the message store.
/// Subscribers will be unable to receive expired messages.
/// Default value is <see cref="TimeSpan.MaxValue"/>.
/// </remarks>
public TimeSpan DefaultMessageTimeToLive
{
get => _defaultMessageTimeToLive;
set
{
Argument.AssertInRange(
value,
AdministrationClientConstants.MinimumAllowedTimeToLive,
AdministrationClientConstants.MaximumAllowedTimeToLive,
nameof(DefaultMessageTimeToLive));
_defaultMessageTimeToLive = value;
}
}
/// <summary>
/// The <see cref="TimeSpan"/> idle interval after which the topic is automatically deleted.
/// </summary>
/// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks>
public TimeSpan AutoDeleteOnIdle
{
get => _autoDeleteOnIdle;
set
{
Argument.AssertAtLeast(
value,
AdministrationClientConstants.MinimumAllowedAutoDeleteOnIdle,
nameof(AutoDeleteOnIdle));
_autoDeleteOnIdle = value;
}
}
/// <summary>
/// The maximum size of the topic in megabytes, which is the size of memory allocated for the topic.
/// </summary>
/// <remarks>Default value is 1024.</remarks>
public long MaxSizeInMegabytes { get; set; } = 1024;
/// <summary>
/// This value indicates if the topic requires guard against duplicate messages. If true, duplicate messages having same
/// <see cref="ServiceBusMessage.MessageId"/> and sent to topic within duration of <see cref="DuplicateDetectionHistoryTimeWindow"/>
/// will be discarded.
/// </summary>
/// <remarks>Defaults to false.</remarks>
public bool RequiresDuplicateDetection { get; set; }
/// <summary>
/// The <see cref="TimeSpan"/> duration of duplicate detection history that is maintained by the service.
/// </summary>
/// <remarks>
/// The default value is 1 minute. Max value is 7 days and minimum is 20 seconds.
/// </remarks>
public TimeSpan DuplicateDetectionHistoryTimeWindow
{
get => _duplicateDetectionHistoryTimeWindow;
set
{
Argument.AssertInRange(
value,
AdministrationClientConstants.MinimumDuplicateDetectionHistoryTimeWindow,
AdministrationClientConstants.MaximumDuplicateDetectionHistoryTimeWindow,
nameof(DuplicateDetectionHistoryTimeWindow));
_duplicateDetectionHistoryTimeWindow = value;
}
}
/// <summary>
/// Name of the topic relative to the namespace base address.
/// </summary>
/// <remarks>Max length is 260 chars. Cannot start or end with a slash.
/// Cannot have restricted characters: '@','?','#','*'</remarks>
public string Name
{
get => _name;
set
{
EntityNameFormatter.CheckValidTopicName(value, nameof(Name));
_name = value;
}
}
/// <summary>
/// The <see cref="AuthorizationRules"/> on the topic to control user access at entity level.
/// </summary>
public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules();
/// <summary>
/// The current status of the topic (Enabled / Disabled).
/// </summary>
/// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks>
public EntityStatus Status { get; set; } = EntityStatus.Active;
/// <summary>
/// Indicates whether the topic is to be partitioned across multiple message brokers.
/// </summary>
/// <remarks>Defaults to false.</remarks>
public bool EnablePartitioning { get; set; }
/// <summary>
/// Defines whether ordering needs to be maintained. If true, messages sent to topic will be
/// forwarded to the subscription in order. For partitioned topics, defaults to false, and
/// setting it to true has no effect.
/// </summary>
/// <remarks>Defaults to false.</remarks>
public bool SupportOrdering { get; set; }
/// <summary>
/// Indicates whether server-side batched operations are enabled.
/// </summary>
/// <remarks>Defaults to true.</remarks>
public bool EnableBatchedOperations { get; set; } = true;
/// <summary>
/// Custom metadata that user can associate with the topic.
/// </summary>
/// <remarks>Cannot be null. Max length is 1024 chars.</remarks>
public string UserMetadata
{
get => _userMetadata;
set
{
Argument.AssertNotNull(value, nameof(UserMetadata));
Argument.AssertNotTooLong(
value,
AdministrationClientConstants.MaxUserMetadataLength,
nameof(UserMetadata));
_userMetadata = value;
}
}
/// <summary>
/// Gets or sets the maximum message size, in kilobytes, for messages sent to this topic.
/// This feature is only available when using a Premium namespace and service version "2021-05" or higher.
/// <seealso href="https://docs.microsoft.com/azure/service-bus-messaging/service-bus-premium-messaging"/>
/// </summary>
public long? MaxMessageSizeInKilobytes { get; set; }
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
public override int GetHashCode()
{
return Name?.GetHashCode() ?? base.GetHashCode();
}
/// <summary>Determines whether the specified object is equal to the current object.</summary>
public override bool Equals(object obj)
{
var other = obj as TopicProperties;
return Equals(other);
}
/// <summary>Determines whether the specified object is equal to the current object.</summary>
public bool Equals(CreateTopicOptions other)
{
if (other is CreateTopicOptions otherOptions
&& Name.Equals(otherOptions.Name, StringComparison.OrdinalIgnoreCase)
&& AutoDeleteOnIdle.Equals(otherOptions.AutoDeleteOnIdle)
&& DefaultMessageTimeToLive.Equals(otherOptions.DefaultMessageTimeToLive)
&& (!RequiresDuplicateDetection || DuplicateDetectionHistoryTimeWindow.Equals(otherOptions.DuplicateDetectionHistoryTimeWindow))
&& EnableBatchedOperations == otherOptions.EnableBatchedOperations
&& EnablePartitioning == otherOptions.EnablePartitioning
&& MaxSizeInMegabytes == otherOptions.MaxSizeInMegabytes
&& RequiresDuplicateDetection.Equals(otherOptions.RequiresDuplicateDetection)
&& Status.Equals(otherOptions.Status)
&& string.Equals(_userMetadata, otherOptions._userMetadata, StringComparison.OrdinalIgnoreCase)
&& (AuthorizationRules != null && otherOptions.AuthorizationRules != null
|| AuthorizationRules == null && otherOptions.AuthorizationRules == null)
&& (AuthorizationRules == null || AuthorizationRules.Equals(otherOptions.AuthorizationRules))
&& MaxMessageSizeInKilobytes.Equals(other.MaxMessageSizeInKilobytes)
&& SupportOrdering == otherOptions.SupportOrdering)
{
return true;
}
return false;
}
/// <summary></summary>
public static bool operator ==(CreateTopicOptions left, CreateTopicOptions right)
{
if (ReferenceEquals(left, right))
{
return true;
}
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return left.Equals(right);
}
/// <summary></summary>
public static bool operator !=(CreateTopicOptions left, CreateTopicOptions right)
{
return !(left == right);
}
}
}