| | 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 | | using Azure.Messaging.EventHubs.Core; |
| | 8 | |
|
| | 9 | | namespace Azure.Messaging.EventHubs.Primitives |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// The set of options that can be specified when creating a <see cref="PartitionReceiver" /> |
| | 13 | | /// to configure its behavior. |
| | 14 | | /// </summary> |
| | 15 | | /// |
| | 16 | | public class PartitionReceiverOptions |
| | 17 | | { |
| | 18 | | /// <summary>The set of options to use for configuring the connection to the Event Hubs service.</summary> |
| 158 | 19 | | private EventHubConnectionOptions _connectionOptions = new EventHubConnectionOptions(); |
| | 20 | |
|
| | 21 | | /// <summary>The set of options to govern retry behavior and try timeouts.</summary> |
| 158 | 22 | | private EventHubsRetryOptions _retryOptions = new EventHubsRetryOptions(); |
| | 23 | |
|
| | 24 | | /// <summary>The amount of time to wait for messages when reading.</summary> |
| 158 | 25 | | private TimeSpan? _defaultMaximumReceiveWaitTime = TimeSpan.FromSeconds(60); |
| | 26 | |
|
| | 27 | | /// <summary>The prefetch count to use for the partition receiver.</summary> |
| 158 | 28 | | private int _prefetchCount = 300; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// The options used for configuring the connection to the Event Hubs service. |
| | 32 | | /// </summary> |
| | 33 | | /// |
| | 34 | | public EventHubConnectionOptions ConnectionOptions |
| | 35 | | { |
| 114 | 36 | | get => _connectionOptions; |
| | 37 | | set |
| | 38 | | { |
| 4 | 39 | | Argument.AssertNotNull(value, nameof(ConnectionOptions)); |
| 2 | 40 | | _connectionOptions = value; |
| 2 | 41 | | } |
| | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// The set of options to use for determining whether a failed operation should be retried and, |
| | 46 | | /// if so, the amount of time to wait between retry attempts. These options also control the |
| | 47 | | /// amount of time allowed for reading events and other interactions with the Event Hubs service. |
| | 48 | | /// </summary> |
| | 49 | | /// |
| | 50 | | public EventHubsRetryOptions RetryOptions |
| | 51 | | { |
| 148 | 52 | | get => _retryOptions; |
| | 53 | | set |
| | 54 | | { |
| 18 | 55 | | Argument.AssertNotNull(value, nameof(RetryOptions)); |
| 16 | 56 | | _retryOptions = value; |
| 16 | 57 | | } |
| | 58 | | } |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// The default amount of time to wait for the requested amount of messages when reading; if this |
| | 62 | | /// period elapses before the requested amount of messages were available or read, then the set of |
| | 63 | | /// messages that were read will be returned. |
| | 64 | | /// </summary> |
| | 65 | | /// |
| | 66 | | public TimeSpan? DefaultMaximumReceiveWaitTime |
| | 67 | | { |
| 144 | 68 | | get => _defaultMaximumReceiveWaitTime; |
| | 69 | |
|
| | 70 | | set |
| | 71 | | { |
| 18 | 72 | | if (value.HasValue) |
| | 73 | | { |
| 14 | 74 | | Argument.AssertNotNegative(value.Value, nameof(DefaultMaximumReceiveWaitTime)); |
| | 75 | | } |
| | 76 | |
|
| 12 | 77 | | _defaultMaximumReceiveWaitTime = value; |
| 12 | 78 | | } |
| | 79 | | } |
| | 80 | |
|
| | 81 | | /// <summary> |
| | 82 | | /// When populated, the owner level indicates that a reading is intended to be performed exclusively for event |
| | 83 | | /// requested partition and for the associated consumer group. To do so, reading will attempt to assert owner |
| | 84 | | /// over the partition; in the case where more than one exclusive reader attempts to assert ownership for the |
| | 85 | | /// partition/consumer group pair, the one having a larger <see cref="OwnerLevel"/> value will "win." |
| | 86 | | /// |
| | 87 | | /// When an exclusive reader is used, other readers which are non-exclusive or which have a lower owner level |
| | 88 | | /// not be allowed to be created, if they already exist, will encounter an exception during the next attempted |
| | 89 | | /// </summary> |
| | 90 | | /// |
| | 91 | | /// <value>The relative priority to associate with an exclusive reader; for a non-exclusive reader, this value s |
| | 92 | | /// |
| | 93 | | /// <remarks> |
| | 94 | | /// An <see cref="EventHubsException"/> will occur if a <see cref="PartitionReceiver"/> is unable to read even |
| | 95 | | /// requested Event Hub partition for the given consumer group. In this case, the <see cref="EventHubsExcepti |
| | 96 | | /// will be set to <see cref="EventHubsException.FailureReason.ConsumerDisconnected"/>. |
| | 97 | | /// </remarks> |
| | 98 | | /// |
| | 99 | | /// <seealso cref="EventHubsException"/> |
| | 100 | | /// <seealso cref="EventHubsException.FailureReason.ConsumerDisconnected"/> |
| | 101 | | /// |
| 198 | 102 | | public long? OwnerLevel { get; set; } |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// The number of events that will be eagerly requested from the Event Hubs service and queued locally without |
| | 106 | | /// whether a read operation is currently active, intended to help maximize throughput by allowing the partiti |
| | 107 | | /// to read from a local cache rather than waiting on a service request. |
| | 108 | | /// </summary> |
| | 109 | | /// |
| | 110 | | /// <value> |
| | 111 | | /// The <see cref="PrefetchCount" /> is a control that developers can use to help tune performance for the spe |
| | 112 | | /// needs of an application, given its expected size of events, throughput needs, and expected scenarios for u |
| | 113 | | /// Event Hubs. |
| | 114 | | /// </value> |
| | 115 | | /// |
| | 116 | | public int PrefetchCount |
| | 117 | | { |
| 162 | 118 | | get => _prefetchCount; |
| | 119 | |
|
| | 120 | | set |
| | 121 | | { |
| 16 | 122 | | Argument.AssertAtLeast(value, 0, nameof(PrefetchCount)); |
| 10 | 123 | | _prefetchCount = value; |
| 10 | 124 | | } |
| | 125 | | } |
| | 126 | |
|
| | 127 | | /// <summary> |
| | 128 | | /// Indicates whether or not the reader should request information on the last enqueued event on the partition |
| | 129 | | /// associated with a given event, and track that information as events are read. |
| | 130 | | /// </summary> |
| | 131 | | /// |
| | 132 | | /// <value><c>true</c> if information about a partition's last event should be requested and tracked; otherwise, |
| | 133 | | /// |
| | 134 | | /// <remarks> |
| | 135 | | /// When information about a partition's last enqueued event is being tracked, each event received from the Ev |
| | 136 | | /// service will carry metadata about the partition that it otherwise would not. This results in a small amoun |
| | 137 | | /// additional network bandwidth consumption that is generally a favorable trade-off when considered |
| | 138 | | /// against periodically making requests for partition properties using one of the Event Hub clients. |
| | 139 | | /// </remarks> |
| | 140 | | /// |
| 360 | 141 | | public bool TrackLastEnqueuedEventProperties { get; set; } = true; |
| | 142 | |
|
| | 143 | | /// <summary> |
| | 144 | | /// Determines whether the specified <see cref="System.Object" /> is equal to this instance. |
| | 145 | | /// </summary> |
| | 146 | | /// |
| | 147 | | /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param> |
| | 148 | | /// |
| | 149 | | /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c> |
| | 150 | | /// |
| | 151 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 152 | | public override bool Equals(object obj) => base.Equals(obj); |
| | 153 | |
|
| | 154 | | /// <summary> |
| | 155 | | /// Returns a hash code for this instance. |
| | 156 | | /// </summary> |
| | 157 | | /// |
| | 158 | | /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a ha |
| | 159 | | /// |
| | 160 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 161 | | public override int GetHashCode() => base.GetHashCode(); |
| | 162 | |
|
| | 163 | | /// <summary> |
| | 164 | | /// Converts the instance to string representation. |
| | 165 | | /// </summary> |
| | 166 | | /// |
| | 167 | | /// <returns>A <see cref="System.String" /> that represents this instance.</returns> |
| | 168 | | /// |
| | 169 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 170 | | public override string ToString() => base.ToString(); |
| | 171 | |
|
| | 172 | | /// <summary> |
| | 173 | | /// Creates a new copy of the current <see cref="PartitionReceiverOptions" />, cloning its attributes into a n |
| | 174 | | /// </summary> |
| | 175 | | /// |
| | 176 | | /// <returns>A new copy of <see cref="PartitionReceiverOptions" />.</returns> |
| | 177 | | /// |
| | 178 | | internal PartitionReceiverOptions Clone() => |
| 26 | 179 | | new PartitionReceiverOptions |
| 26 | 180 | | { |
| 26 | 181 | | _connectionOptions = ConnectionOptions.Clone(), |
| 26 | 182 | | _retryOptions = RetryOptions.Clone(), |
| 26 | 183 | | _defaultMaximumReceiveWaitTime = DefaultMaximumReceiveWaitTime, |
| 26 | 184 | | OwnerLevel = OwnerLevel, |
| 26 | 185 | | _prefetchCount = PrefetchCount, |
| 26 | 186 | | TrackLastEnqueuedEventProperties = TrackLastEnqueuedEventProperties |
| 26 | 187 | | }; |
| | 188 | | } |
| | 189 | | } |