| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.ComponentModel; |
| | 6 | | using Azure.Core; |
| | 7 | |
|
| | 8 | | namespace Azure.Messaging.ServiceBus |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// The set of options that can be specified when creating a |
| | 12 | | /// <see cref="ServiceBusSessionProcessor" /> |
| | 13 | | /// to configure its behavior. |
| | 14 | | /// </summary> |
| | 15 | | public class ServiceBusSessionProcessorOptions |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// The number of messages that will be eagerly requested from Queues or Subscriptions and queued locally withou |
| | 19 | | /// whether a processing is currently active, intended to help maximize throughput by allowing the receiver to r |
| | 20 | | /// from a local cache rather than waiting on a service request. |
| | 21 | | /// </summary> |
| | 22 | | public int PrefetchCount |
| | 23 | | { |
| | 24 | | get |
| | 25 | | { |
| 16 | 26 | | return _prefetchCount; |
| | 27 | | } |
| | 28 | | set |
| | 29 | | { |
| 6 | 30 | | Argument.AssertAtLeast(value, 0, nameof(PrefetchCount)); |
| 4 | 31 | | _prefetchCount = value; |
| 4 | 32 | | } |
| | 33 | | } |
| | 34 | | private int _prefetchCount = 0; |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// The <see cref="ReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode. |
| | 38 | | /// </summary> |
| 18 | 39 | | public ReceiveMode ReceiveMode { get; set; } = ReceiveMode.PeekLock; |
| | 40 | |
|
| | 41 | | /// <summary>Gets or sets a value that indicates whether |
| | 42 | | /// the processor should automatically complete messages |
| | 43 | | /// after the callback has completed processing. |
| | 44 | | /// The default value is true.</summary> |
| | 45 | | /// <value>true to complete the message processing automatically on successful execution of the operation; other |
| 34 | 46 | | public bool AutoComplete { get; set; } = true; |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets or sets the maximum duration within which the lock will be renewed automatically. This value should be |
| | 50 | | /// greater than the queue's LockDuration Property. |
| | 51 | | /// </summary> |
| | 52 | | /// |
| | 53 | | /// <value>The maximum duration during which locks are automatically renewed.</value> |
| | 54 | | public TimeSpan MaxAutoLockRenewalDuration |
| | 55 | | { |
| 16 | 56 | | get => _maxAutoRenewDuration; |
| | 57 | |
|
| | 58 | | set |
| | 59 | | { |
| 6 | 60 | | Argument.AssertNotNegative(value, nameof(MaxAutoLockRenewalDuration)); |
| 4 | 61 | | _maxAutoRenewDuration = value; |
| 4 | 62 | | } |
| | 63 | | } |
| 16 | 64 | | private TimeSpan _maxAutoRenewDuration = TimeSpan.FromMinutes(5); |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// The maximum amount of time to wait for each Receive call using the processor's underlying receiver. |
| | 68 | | /// If not specified, the <see cref="ServiceBusRetryOptions.TryTimeout"/> will be used. |
| | 69 | | /// </summary> |
| | 70 | | public TimeSpan? MaxReceiveWaitTime |
| | 71 | | { |
| 14 | 72 | | get => _maxReceiveWaitTime; |
| | 73 | |
|
| | 74 | | set |
| | 75 | | { |
| 6 | 76 | | if (value.HasValue) |
| | 77 | | { |
| 6 | 78 | | Argument.AssertPositive(value.Value, nameof(MaxReceiveWaitTime)); |
| | 79 | | } |
| | 80 | |
|
| 2 | 81 | | _maxReceiveWaitTime = value; |
| 2 | 82 | | } |
| | 83 | | } |
| | 84 | | private TimeSpan? _maxReceiveWaitTime; |
| | 85 | |
|
| | 86 | | /// <summary>Gets or sets the maximum number of sessions that can be processed concurrently by the processor. |
| | 87 | | /// The default value is 8.</summary> |
| | 88 | | /// <value>The maximum number of concurrent sessions to process.</value> |
| | 89 | | public int MaxConcurrentSessions |
| | 90 | | { |
| 16 | 91 | | get => _maxConcurrentSessions; |
| | 92 | |
|
| | 93 | | set |
| | 94 | | { |
| 4 | 95 | | Argument.AssertAtLeast(value, 1, nameof(MaxConcurrentSessions)); |
| 2 | 96 | | _maxConcurrentSessions = value; |
| 2 | 97 | | } |
| | 98 | | } |
| 16 | 99 | | private int _maxConcurrentSessions = 8; |
| | 100 | |
|
| | 101 | | /// <summary>Gets or sets the maximum number of calls to the callback the processor should initiate per session. |
| | 102 | | /// Thus the total number of callbacks will be equal to MaxConcurrentSessions * MaxConcurrentCallsPerSession. |
| | 103 | | /// The default value is 1.</summary> |
| | 104 | | /// <value>The maximum number of concurrent calls to the callback for each session that is being processed.</val |
| | 105 | | public int MaxConcurrentCallsPerSession |
| | 106 | | { |
| 16 | 107 | | get => _maxConcurrentCallsPerSessions; |
| | 108 | |
|
| | 109 | | set |
| | 110 | | { |
| 4 | 111 | | Argument.AssertAtLeast(value, 1, nameof(MaxConcurrentCallsPerSession)); |
| 2 | 112 | | _maxConcurrentCallsPerSessions = value; |
| 2 | 113 | | } |
| | 114 | | } |
| 16 | 115 | | private int _maxConcurrentCallsPerSessions = 1; |
| | 116 | |
|
| | 117 | | /// <summary> |
| | 118 | | /// An optional list of session IDs to scope |
| | 119 | | /// the <see cref="ServiceBusSessionProcessor"/> to. If left |
| | 120 | | /// blank, the processor will not be limited to any specific |
| | 121 | | /// session IDs. |
| | 122 | | /// </summary> |
| 0 | 123 | | public string[] SessionIds { get; set; } |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Determines whether the specified <see cref="System.Object" /> is equal to this instance. |
| | 127 | | /// </summary> |
| | 128 | | /// |
| | 129 | | /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param> |
| | 130 | | /// |
| | 131 | | /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c> |
| | 132 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 133 | | public override bool Equals(object obj) => base.Equals(obj); |
| | 134 | |
|
| | 135 | | /// <summary> |
| | 136 | | /// Returns a hash code for this instance. |
| | 137 | | /// </summary> |
| | 138 | | /// |
| | 139 | | /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a ha |
| | 140 | | /// |
| | 141 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 142 | | public override int GetHashCode() => base.GetHashCode(); |
| | 143 | |
|
| | 144 | | /// <summary> |
| | 145 | | /// Converts the instance to string representation. |
| | 146 | | /// </summary> |
| | 147 | | /// |
| | 148 | | /// <returns>A <see cref="System.String" /> that represents this instance.</returns> |
| | 149 | | /// |
| | 150 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 151 | | public override string ToString() => base.ToString(); |
| | 152 | |
|
| | 153 | | internal ServiceBusProcessorOptions ToProcessorOptions() => |
| 14 | 154 | | new ServiceBusProcessorOptions |
| 14 | 155 | | { |
| 14 | 156 | | ReceiveMode = ReceiveMode, |
| 14 | 157 | | PrefetchCount = PrefetchCount, |
| 14 | 158 | | AutoComplete = AutoComplete, |
| 14 | 159 | | MaxAutoLockRenewalDuration = MaxAutoLockRenewalDuration, |
| 14 | 160 | | MaxReceiveWaitTime = MaxReceiveWaitTime |
| 14 | 161 | | }; |
| | 162 | | } |
| | 163 | | } |