| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.ComponentModel; |
| | 5 | |
|
| | 6 | | namespace Azure.Messaging.EventHubs.Producer |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// The set of options that can be specified to influence the way in which events |
| | 10 | | /// are published to the Event Hubs service. |
| | 11 | | /// </summary> |
| | 12 | | /// |
| | 13 | | public class SendEventOptions |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Allows a hashing key to be provided for the batch of events, which instructs the Event Hubs |
| | 17 | | /// service map this key to a specific partition but allowing the service to choose an arbitrary, |
| | 18 | | /// partition for this batch of events and any other batches using the same partition hashing key. |
| | 19 | | /// |
| | 20 | | /// The selection of a partition is stable for a given partition hashing key. Should any other |
| | 21 | | /// batches of events be sent using the same exact partition hashing key, the Event Hubs service will |
| | 22 | | /// route them all to the same partition. |
| | 23 | | /// |
| | 24 | | /// This should be specified only when there is a need to group events by partition, but there is |
| | 25 | | /// flexibility into which partition they are routed. If ensuring that a batch of events is sent |
| | 26 | | /// only to a specific partition, it is recommended that the identifier of the position be |
| | 27 | | /// specified directly when sending the batch. |
| | 28 | | /// </summary> |
| | 29 | | /// |
| | 30 | | /// <value> |
| | 31 | | /// If the producer wishes to influence the automatic routing of events to partitions, the partition |
| | 32 | | /// hashing key to associate with the event or batch of events; otherwise, <c>null</c>. |
| | 33 | | /// </value> |
| | 34 | | /// |
| | 35 | | /// <remarks> |
| | 36 | | /// If the <see cref="SendEventOptions.PartitionKey" /> is specified, then no <see cref="SendEventOptions.Part |
| | 37 | | /// may be set when sending. |
| | 38 | | /// </remarks> |
| | 39 | | /// |
| 432 | 40 | | public string PartitionKey { get; set; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// If specified, events be published to this specific partition. If the identifier is not |
| | 44 | | /// specified, the Event Hubs service will be responsible for routing events automatically to an available par |
| | 45 | | /// </summary> |
| | 46 | | /// |
| | 47 | | /// <value> |
| | 48 | | /// If the producer wishes the events to be automatically to partitions, <c>null</c>; otherwise, the identifie |
| | 49 | | /// of the desired partition. |
| | 50 | | /// </value> |
| | 51 | | /// |
| | 52 | | /// <remarks> |
| | 53 | | /// If the <see cref="SendEventOptions.PartitionId" /> is specified, then no <see cref="SendEventOptions.Parti |
| | 54 | | /// may be set when sending. |
| | 55 | | /// |
| | 56 | | /// <para>Allowing automatic routing of partitions is recommended when:</para> |
| | 57 | | /// <para>- The sending of events needs to be highly available.</para> |
| | 58 | | /// <para>- The event data should be evenly distributed among all available partitions.</para> |
| | 59 | | /// |
| | 60 | | /// If no partition is specified, the following rules are used for automatically selecting one: |
| | 61 | | /// <para>1) Distribute the events equally amongst all available partitions using a round-robin approach.</par |
| | 62 | | /// <para>2) If a partition becomes unavailable, the Event Hubs service will automatically detect it and forwa |
| | 63 | | /// </remarks> |
| | 64 | | /// |
| 286 | 65 | | public string PartitionId { get; set; } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Initializes a new instance of the <see cref="SendEventOptions"/> class. |
| | 69 | | /// </summary> |
| | 70 | | /// |
| 260 | 71 | | public SendEventOptions() |
| | 72 | | { |
| 260 | 73 | | } |
| | 74 | |
|
| | 75 | | /// <summary> |
| | 76 | | /// Initializes a new instance of the <see cref="SendEventOptions"/> class. |
| | 77 | | /// </summary> |
| | 78 | | /// |
| | 79 | | /// <param name="partitionId">The identifier of the partition to which events should be sent.</param> |
| | 80 | | /// <param name="partitionKey">The hashing key to use for influencing the partition to which the events are rout |
| | 81 | | /// |
| 0 | 82 | | internal SendEventOptions(string partitionId, |
| 0 | 83 | | string partitionKey) |
| | 84 | | { |
| 0 | 85 | | PartitionId = partitionId; |
| 0 | 86 | | PartitionKey = partitionKey; |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Determines whether the specified <see cref="System.Object" /> is equal to this instance. |
| | 91 | | /// </summary> |
| | 92 | | /// |
| | 93 | | /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param> |
| | 94 | | /// |
| | 95 | | /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c> |
| | 96 | | /// |
| | 97 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 98 | | public override bool Equals(object obj) => base.Equals(obj); |
| | 99 | |
|
| | 100 | | /// <summary> |
| | 101 | | /// Returns a hash code for this instance. |
| | 102 | | /// </summary> |
| | 103 | | /// |
| | 104 | | /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a ha |
| | 105 | | /// |
| | 106 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 107 | | public override int GetHashCode() => base.GetHashCode(); |
| | 108 | |
|
| | 109 | | /// <summary> |
| | 110 | | /// Converts the instance to string representation. |
| | 111 | | /// </summary> |
| | 112 | | /// |
| | 113 | | /// <returns>A <see cref="System.String" /> that represents this instance.</returns> |
| | 114 | | /// |
| | 115 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 116 | | public override string ToString() => base.ToString(); |
| | 117 | | } |
| | 118 | | } |