| | 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 baseline set of options that can be specified when creating a <see cref="ServiceBusProcessor" /> |
| | 12 | | /// to configure its behavior. |
| | 13 | | /// </summary> |
| | 14 | | public class ServiceBusProcessorOptions |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// The number of messages that will be eagerly requested from Queues or Subscriptions and queued locally withou |
| | 18 | | /// whether a processing is currently active, intended to help maximize throughput by allowing the receiver to r |
| | 19 | | /// from a local cache rather than waiting on a service request. |
| | 20 | | /// </summary> |
| | 21 | | public int PrefetchCount |
| | 22 | | { |
| | 23 | | get |
| | 24 | | { |
| 74 | 25 | | return _prefetchCount; |
| | 26 | | } |
| | 27 | | set |
| | 28 | | { |
| 54 | 29 | | Argument.AssertAtLeast(value, 0, nameof(PrefetchCount)); |
| 52 | 30 | | _prefetchCount = value; |
| 52 | 31 | | } |
| | 32 | | } |
| | 33 | | private int _prefetchCount = 0; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// The <see cref="ReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode. |
| | 37 | | /// </summary> |
| 124 | 38 | | public ReceiveMode ReceiveMode { get; set; } = ReceiveMode.PeekLock; |
| | 39 | |
|
| | 40 | | /// <summary>Gets or sets a value that indicates whether the processor should call |
| | 41 | | /// Receiver.CompleteAsync() on messages after the callback has completed processing. |
| | 42 | | /// The default value is true.</summary> |
| | 43 | | /// <value>true to complete the message processing automatically on successful execution of the operation; other |
| 200 | 44 | | public bool AutoComplete { get; set; } = true; |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Gets or sets the maximum duration within which the lock will be renewed automatically. This |
| | 48 | | /// value should be greater than the longest message lock duration; for example, the LockDuration Property. |
| | 49 | | /// </summary> |
| | 50 | | /// |
| | 51 | | /// <value>The maximum duration during which locks are automatically renewed.</value> |
| | 52 | | /// |
| | 53 | | /// <remarks>The message renew can continue for sometime in the background |
| | 54 | | /// after completion of message and result in a few false MessageLockLostExceptions temporarily.</remarks> |
| | 55 | | public TimeSpan MaxAutoLockRenewalDuration |
| | 56 | | { |
| 74 | 57 | | get => _maxAutoRenewDuration; |
| | 58 | |
|
| | 59 | | set |
| | 60 | | { |
| 60 | 61 | | Argument.AssertNotNegative(value, nameof(MaxAutoLockRenewalDuration)); |
| 58 | 62 | | _maxAutoRenewDuration = value; |
| 58 | 63 | | } |
| | 64 | | } |
| 70 | 65 | | private TimeSpan _maxAutoRenewDuration = TimeSpan.FromMinutes(5); |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// The maximum amount of time to wait for each Receive call using the processor's underlying receiver. |
| | 69 | | /// If not specified, the <see cref="ServiceBusRetryOptions.TryTimeout"/> will be used. |
| | 70 | | /// </summary> |
| | 71 | | /// <remarks>When using a <see cref="ServiceBusSessionProcessor"/>, if no message is returned for a call |
| | 72 | | /// to Receive, a new session will be requested by the processor. |
| | 73 | | /// Hence, if this value is set to be too low, it could cause new sessions to be requested |
| | 74 | | /// more often than necessary.</remarks> |
| | 75 | | public TimeSpan? MaxReceiveWaitTime |
| | 76 | | { |
| 74 | 77 | | get => _maxReceiveWaitTime; |
| | 78 | |
|
| | 79 | | set |
| | 80 | | { |
| 56 | 81 | | if (value.HasValue) |
| | 82 | | { |
| 10 | 83 | | Argument.AssertPositive(value.Value, nameof(MaxReceiveWaitTime)); |
| | 84 | | } |
| | 85 | |
|
| 52 | 86 | | _maxReceiveWaitTime = value; |
| 52 | 87 | | } |
| | 88 | | } |
| | 89 | | private TimeSpan? _maxReceiveWaitTime; |
| | 90 | |
|
| | 91 | | /// <summary>Gets or sets the maximum number of concurrent calls to the callback the processor should initiate. |
| | 92 | | /// The default is 1.</summary> |
| | 93 | | /// <value>The maximum number of concurrent calls to the callback.</value> |
| | 94 | | public int MaxConcurrentCalls |
| | 95 | | { |
| 70 | 96 | | get => _maxConcurrentCalls; |
| | 97 | |
|
| | 98 | | set |
| | 99 | | { |
| 40 | 100 | | Argument.AssertAtLeast(value, 1, nameof(MaxConcurrentCalls)); |
| 36 | 101 | | _maxConcurrentCalls = value; |
| 36 | 102 | | } |
| | 103 | | } |
| 70 | 104 | | private int _maxConcurrentCalls = 1; |
| | 105 | |
|
| | 106 | | /// <summary> |
| | 107 | | /// Determines whether the specified <see cref="System.Object" /> is equal to this instance. |
| | 108 | | /// </summary> |
| | 109 | | /// |
| | 110 | | /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param> |
| | 111 | | /// |
| | 112 | | /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c> |
| | 113 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 114 | | public override bool Equals(object obj) => base.Equals(obj); |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// Returns a hash code for this instance. |
| | 118 | | /// </summary> |
| | 119 | | /// |
| | 120 | | /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a ha |
| | 121 | | /// |
| | 122 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 123 | | public override int GetHashCode() => base.GetHashCode(); |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Converts the instance to string representation. |
| | 127 | | /// </summary> |
| | 128 | | /// |
| | 129 | | /// <returns>A <see cref="System.String" /> that represents this instance.</returns> |
| | 130 | | /// |
| | 131 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 132 | | public override string ToString() => base.ToString(); |
| | 133 | |
|
| | 134 | | /// <summary> |
| | 135 | | /// Creates a new copy of the current <see cref="ServiceBusProcessorOptions" />, cloning its attributes into a n |
| | 136 | | /// </summary> |
| | 137 | | /// |
| | 138 | | /// <returns>A new copy of <see cref="ServiceBusProcessorOptions" />.</returns> |
| | 139 | | internal ServiceBusProcessorOptions Clone() |
| | 140 | | { |
| 34 | 141 | | return new ServiceBusProcessorOptions |
| 34 | 142 | | { |
| 34 | 143 | | ReceiveMode = ReceiveMode, |
| 34 | 144 | | PrefetchCount = PrefetchCount, |
| 34 | 145 | | AutoComplete = AutoComplete, |
| 34 | 146 | | MaxAutoLockRenewalDuration = MaxAutoLockRenewalDuration, |
| 34 | 147 | | MaxReceiveWaitTime = MaxReceiveWaitTime, |
| 34 | 148 | | MaxConcurrentCalls = MaxConcurrentCalls |
| 34 | 149 | | }; |
| | 150 | | } |
| | 151 | | } |
| | 152 | | } |