-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
CreateSubscriptionOptions.cs
353 lines (318 loc) · 14.3 KB
/
CreateSubscriptionOptions.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Azure.Core;
namespace Azure.Messaging.ServiceBus.Administration
{
/// <summary>
/// Represents the metadata description of the subscription.
/// </summary>
public class CreateSubscriptionOptions : IEquatable<CreateSubscriptionOptions>
{
private string _topicName, _subscriptionName;
private TimeSpan _lockDuration = TimeSpan.FromSeconds(60);
private TimeSpan _defaultMessageTimeToLive = TimeSpan.MaxValue;
private TimeSpan _autoDeleteOnIdle = TimeSpan.MaxValue;
private int _maxDeliveryCount = 10;
private string _forwardTo;
private string _forwardDeadLetteredMessagesTo;
private string _userMetadata;
/// <summary>
/// Initializes a new instance of SubscriptionDescription class with the specified name and topic name.
/// </summary>
/// <param name="topicName">Name of the topic relative to the namespace base address.</param>
/// <param name="subscriptionName">Name of the subscription.</param>
public CreateSubscriptionOptions(string topicName, string subscriptionName)
{
TopicName = topicName;
SubscriptionName = subscriptionName;
}
/// <summary>
/// Initializes a new instance of <see cref="CreateSubscriptionOptions"/> based on the
/// specified <see cref="SubscriptionProperties"/> instance. This is useful for creating a new subscription based
/// on the properties of an existing subscription.
/// </summary>
/// <param name="subscription">Existing subscription to create options from.</param>
public CreateSubscriptionOptions(SubscriptionProperties subscription)
{
Argument.AssertNotNull(subscription, nameof(subscription));
TopicName = subscription.TopicName;
SubscriptionName = subscription.SubscriptionName;
LockDuration = subscription.LockDuration;
RequiresSession = subscription.RequiresSession;
DefaultMessageTimeToLive = subscription.DefaultMessageTimeToLive;
AutoDeleteOnIdle = subscription.AutoDeleteOnIdle;
DeadLetteringOnMessageExpiration = subscription.DeadLetteringOnMessageExpiration;
EnableDeadLetteringOnFilterEvaluationExceptions = subscription.EnableDeadLetteringOnFilterEvaluationExceptions;
MaxDeliveryCount = subscription.MaxDeliveryCount;
EnableBatchedOperations = subscription.EnableBatchedOperations;
Status = subscription.Status;
ForwardTo = subscription.ForwardTo;
ForwardDeadLetteredMessagesTo = subscription.ForwardDeadLetteredMessagesTo;
if (subscription.UserMetadata != null)
{
UserMetadata = subscription.UserMetadata;
}
}
/// <summary>
/// Duration of a peek lock receive. i.e., the amount of time that the message is locked by a given receiver so that
/// no other receiver receives the same message.
/// </summary>
/// <remarks>Max value is 5 minutes. Default value is 60 seconds.</remarks>
public TimeSpan LockDuration
{
get => _lockDuration;
set
{
Argument.AssertPositive(value, nameof(LockDuration));
_lockDuration = value;
}
}
/// <summary>
/// This indicates whether the subscription supports the concept of session. Sessionful-messages follow FIFO ordering.
/// </summary>
/// <remarks>
/// If true, the receiver can only receive messages using <see cref="ServiceBusSessionProcessor"/>.
/// Defaults to false.
/// </remarks>
public bool RequiresSession { get; set; }
/// <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 subscription 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>
/// Indicates whether this subscription has dead letter support when a message expires.
/// </summary>
/// <remarks>If true, the expired messages are moved to dead-letter subqueue. Default value is false.</remarks>
public bool DeadLetteringOnMessageExpiration { get; set; }
/// <summary>
/// indicates whether messages need to be forwarded to dead-letter sub queue when subscription rule evaluation fails.
/// </summary>
/// <remarks>Defaults to true.</remarks>
public bool EnableDeadLetteringOnFilterEvaluationExceptions { get; set; } = true;
/// <summary>
/// Name of the topic under which subscription exists.
/// </summary>
/// <remarks>Value cannot be null or empty. Value cannot exceed 260 chars. Cannot start or end with a slash.
/// Cannot have restricted characters: '@','?','#','*'</remarks>
public string TopicName
{
get => _topicName;
set
{
EntityNameFormatter.CheckValidTopicName(value, nameof(TopicName));
_topicName = value;
}
}
/// <summary>
/// Name of the subscription.
/// </summary>
/// <remarks>Value cannot be null or empty. Value cannot exceed 50 chars.
/// Cannot have restricted characters: '@','?','#','*','/','\'</remarks>
public string SubscriptionName
{
get => _subscriptionName;
set
{
EntityNameFormatter.CheckValidSubscriptionName(value, nameof(SubscriptionName));
_subscriptionName = value;
}
}
/// <summary>
/// The maximum delivery count of a message before it is dead-lettered.
/// </summary>
/// <remarks>The delivery count is increased when a message is received in <see cref="ServiceBusReceiveMode.PeekLock"/> mode
/// and didn't complete the message before the message lock expired.
/// Default value is 10. Minimum value is 1.</remarks>
public int MaxDeliveryCount
{
get => _maxDeliveryCount;
set
{
Argument.AssertAtLeast(
value,
AdministrationClientConstants.MinAllowedMaxDeliveryCount,
nameof(MaxDeliveryCount));
_maxDeliveryCount = value;
}
}
/// <summary>
/// The current status of the subscription (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>
/// The name of the recipient entity to which all the messages sent to the subscription are forwarded to.
/// </summary>
/// <remarks>If set, user cannot manually receive messages from this subscription. The destination entity
/// must be an already existing entity.</remarks>
public string ForwardTo
{
get => _forwardTo;
set
{
if (string.IsNullOrWhiteSpace(value))
{
_forwardTo = value;
return;
}
EntityNameFormatter.CheckValidQueueName(value, nameof(ForwardTo));
if (_topicName.Equals(value, StringComparison.CurrentCultureIgnoreCase))
{
throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself");
}
_forwardTo = value;
}
}
/// <summary>
/// The name of the recipient entity to which all the dead-lettered messages of this subscription are forwarded to.
/// </summary>
/// <remarks>If set, user cannot manually receive dead-lettered messages from this subscription. The destination
/// entity must already exist.</remarks>
public string ForwardDeadLetteredMessagesTo
{
get => _forwardDeadLetteredMessagesTo;
set
{
if (string.IsNullOrWhiteSpace(value))
{
_forwardDeadLetteredMessagesTo = value;
return;
}
EntityNameFormatter.CheckValidQueueName(value, nameof(ForwardDeadLetteredMessagesTo));
if (_topicName.Equals(value, StringComparison.CurrentCultureIgnoreCase))
{
throw new InvalidOperationException("Entity cannot have auto-forwarding policy to itself");
}
_forwardDeadLetteredMessagesTo = value;
}
}
/// <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 subscription.
/// </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>
/// Returns a hash code for this instance.
/// </summary>
public override int GetHashCode()
{
int hash = 7;
unchecked
{
hash = (hash * 7) + TopicName?.GetHashCode() ?? 0;
hash = (hash * 7) + SubscriptionName?.GetHashCode() ?? 0;
}
return hash;
}
/// <summary>Determines whether the specified object is equal to the current object.</summary>
public override bool Equals(object obj)
{
var other = obj as CreateSubscriptionOptions;
return Equals(other);
}
/// <summary>Determines whether the specified object is equal to the current object.</summary>
public bool Equals(CreateSubscriptionOptions other)
{
if (other is CreateSubscriptionOptions otherOptions
&& SubscriptionName.Equals(otherOptions.SubscriptionName, StringComparison.OrdinalIgnoreCase)
&& TopicName.Equals(otherOptions.TopicName, StringComparison.OrdinalIgnoreCase)
&& AutoDeleteOnIdle.Equals(otherOptions.AutoDeleteOnIdle)
&& DefaultMessageTimeToLive.Equals(otherOptions.DefaultMessageTimeToLive)
&& EnableBatchedOperations == otherOptions.EnableBatchedOperations
&& DeadLetteringOnMessageExpiration == otherOptions.DeadLetteringOnMessageExpiration
&& EnableDeadLetteringOnFilterEvaluationExceptions == otherOptions.EnableDeadLetteringOnFilterEvaluationExceptions
&& string.Equals(ForwardDeadLetteredMessagesTo, otherOptions.ForwardDeadLetteredMessagesTo, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ForwardTo, otherOptions.ForwardTo, StringComparison.OrdinalIgnoreCase)
&& LockDuration.Equals(otherOptions.LockDuration)
&& MaxDeliveryCount == otherOptions.MaxDeliveryCount
&& RequiresSession.Equals(otherOptions.RequiresSession)
&& Status.Equals(otherOptions.Status)
&& string.Equals(_userMetadata, otherOptions._userMetadata, StringComparison.OrdinalIgnoreCase))
{
return true;
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator ==(CreateSubscriptionOptions left, CreateSubscriptionOptions right)
{
if (ReferenceEquals(left, right))
{
return true;
}
if (left is null || right is null)
{
return false;
}
return left.Equals(right);
}
/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator !=(CreateSubscriptionOptions left, CreateSubscriptionOptions right)
{
return !(left == right);
}
}
}