| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Threading; |
| | 6 | | using System.Threading.Tasks; |
| | 7 | | using Azure.Messaging.EventHubs.Consumer; |
| | 8 | |
|
| | 9 | | namespace Azure.Messaging.EventHubs.Core |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Provides an abstraction for generalizing an Event Hub client so that a dedicated instance may provide operatio |
| | 13 | | /// for a specific transport, such as AMQP or JMS. It is intended that the public <see cref="EventHubConnection" |
| | 14 | | /// a transport client via containment and delegate operations to it rather than understanding protocol-specific d |
| | 15 | | /// for different transports. |
| | 16 | | /// </summary> |
| | 17 | | /// |
| | 18 | | internal abstract class TransportClient : IAsyncDisposable |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// Indicates whether or not this client has been closed. |
| | 22 | | /// </summary> |
| | 23 | | /// |
| | 24 | | /// <value> |
| | 25 | | /// <c>true</c> if the client is closed; otherwise, <c>false</c>. |
| | 26 | | /// </value> |
| | 27 | | /// |
| 0 | 28 | | public virtual bool IsClosed { get; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// The endpoint for the Event Hubs service to which the client is associated. |
| | 32 | | /// </summary> |
| | 33 | | /// |
| 0 | 34 | | public virtual Uri ServiceEndpoint { get; } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Retrieves information about an Event Hub, including the number of partitions present |
| | 38 | | /// and their identifiers. |
| | 39 | | /// </summary> |
| | 40 | | /// |
| | 41 | | /// <param name="retryPolicy">The retry policy to use as the basis for retrieving the information.</param> |
| | 42 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 43 | | /// |
| | 44 | | /// <returns>The set of information for the Event Hub that this client is associated with.</returns> |
| | 45 | | /// |
| | 46 | | public abstract Task<EventHubProperties> GetPropertiesAsync(EventHubsRetryPolicy retryPolicy, |
| | 47 | | CancellationToken cancellationToken); |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Retrieves information about a specific partition for an Event Hub, including elements that describe the av |
| | 51 | | /// events in the partition event stream. |
| | 52 | | /// </summary> |
| | 53 | | /// |
| | 54 | | /// <param name="partitionId">The unique identifier of a partition associated with the Event Hub.</param> |
| | 55 | | /// <param name="retryPolicy">The retry policy to use as the basis for retrieving the information.</param> |
| | 56 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 57 | | /// |
| | 58 | | /// <returns>The set of information for the requested partition under the Event Hub this client is associated wi |
| | 59 | | /// |
| | 60 | | public abstract Task<PartitionProperties> GetPartitionPropertiesAsync(string partitionId, |
| | 61 | | EventHubsRetryPolicy retryPolicy, |
| | 62 | | CancellationToken cancellationToken); |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// Creates a producer strongly aligned with the active protocol and transport, |
| | 66 | | /// responsible for publishing <see cref="EventData" /> to the Event Hub. |
| | 67 | | /// </summary> |
| | 68 | | /// |
| | 69 | | /// <param name="partitionId">The identifier of the partition to which the transport producer should be bound; i |
| | 70 | | /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> |
| | 71 | | /// |
| | 72 | | /// <returns>A <see cref="TransportProducer"/> configured in the requested manner.</returns> |
| | 73 | | /// |
| | 74 | | public abstract TransportProducer CreateProducer(string partitionId, |
| | 75 | | EventHubsRetryPolicy retryPolicy); |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Creates a consumer strongly aligned with the active protocol and transport, responsible |
| | 79 | | /// for reading <see cref="EventData" /> from a specific Event Hub partition, in the context |
| | 80 | | /// of a specific consumer group. |
| | 81 | | /// |
| | 82 | | /// A consumer may be exclusive, which asserts ownership over the partition for the consumer |
| | 83 | | /// group to ensure that only one consumer from that group is reading the from the partition. |
| | 84 | | /// These exclusive consumers are sometimes referred to as "Epoch Consumers." |
| | 85 | | /// |
| | 86 | | /// A consumer may also be non-exclusive, allowing multiple consumers from the same consumer |
| | 87 | | /// group to be actively reading events from the partition. These non-exclusive consumers are |
| | 88 | | /// sometimes referred to as "Non-epoch Consumers." |
| | 89 | | /// |
| | 90 | | /// Designating a consumer as exclusive may be specified by setting the <paramref name="ownerLevel" />. |
| | 91 | | /// When <c>null</c>, consumers are created as non-exclusive. |
| | 92 | | /// </summary> |
| | 93 | | /// |
| | 94 | | /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are rea |
| | 95 | | /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</par |
| | 96 | | /// <param name="eventPosition">The position within the partition where the consumer should begin reading events |
| | 97 | | /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> |
| | 98 | | /// <param name="trackLastEnqueuedEventProperties">Indicates whether information on the last enqueued event on t |
| | 99 | | /// <param name="ownerLevel">The relative priority to associate with the link; for a non-exclusive link, this va |
| | 100 | | /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whet |
| | 101 | | /// |
| | 102 | | /// <returns>A <see cref="TransportConsumer" /> configured in the requested manner.</returns> |
| | 103 | | /// |
| | 104 | | public abstract TransportConsumer CreateConsumer(string consumerGroup, |
| | 105 | | string partitionId, |
| | 106 | | EventPosition eventPosition, |
| | 107 | | EventHubsRetryPolicy retryPolicy, |
| | 108 | | bool trackLastEnqueuedEventProperties, |
| | 109 | | long? ownerLevel, |
| | 110 | | uint? prefetchCount); |
| | 111 | |
|
| | 112 | | /// <summary> |
| | 113 | | /// Closes the connection to the transport client instance. |
| | 114 | | /// </summary> |
| | 115 | | /// |
| | 116 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 117 | | /// |
| | 118 | | public abstract Task CloseAsync(CancellationToken cancellationToken); |
| | 119 | |
|
| | 120 | | /// <summary> |
| | 121 | | /// Performs the task needed to clean up resources used by the client, |
| | 122 | | /// including ensuring that the client itself has been closed. |
| | 123 | | /// </summary> |
| | 124 | | /// |
| | 125 | | /// <returns>A task to be resolved on when the operation has completed.</returns> |
| | 126 | | /// |
| 2 | 127 | | public virtual async ValueTask DisposeAsync() => await CloseAsync(CancellationToken.None).ConfigureAwait(false); |
| | 128 | | } |
| | 129 | | } |