| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Threading; |
| | 6 | | using System.Threading.Tasks; |
| | 7 | | using Azure.Messaging.EventHubs.Producer; |
| | 8 | |
|
| | 9 | | namespace Azure.Messaging.EventHubs.Core |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Provides an abstraction for generalizing an Event Hub Producer so that a dedicated instance may provide operat |
| | 13 | | /// for a specific transport, such as AMQP or JMS. It is intended that the public <see cref="EventHubProducerClie |
| | 14 | | /// a transport producer via containment and delegate operations to it rather than understanding protocol-specific |
| | 15 | | /// for different transports. |
| | 16 | | /// </summary> |
| | 17 | | /// |
| | 18 | | internal abstract class TransportProducer |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// Indicates whether or not this producer has been closed. |
| | 22 | | /// </summary> |
| | 23 | | /// |
| | 24 | | /// <value> |
| | 25 | | /// <c>true</c> if the producer is closed; otherwise, <c>false</c>. |
| | 26 | | /// </value> |
| | 27 | | /// |
| 14 | 28 | | public virtual bool IsClosed { get; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Sends a set of events to the associated Event Hub using a batched approach. If the size of events exceed |
| | 32 | | /// maximum size of a single batch, an exception will be triggered and the send will fail. |
| | 33 | | /// </summary> |
| | 34 | | /// |
| | 35 | | /// <param name="events">The set of event data to send.</param> |
| | 36 | | /// <param name="sendOptions">The set of options to consider when sending this batch.</param> |
| | 37 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 38 | | /// |
| | 39 | | public abstract Task SendAsync(IEnumerable<EventData> events, |
| | 40 | | SendEventOptions sendOptions, |
| | 41 | | CancellationToken cancellationToken); |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Sends a set of events to the associated Event Hub using a batched approach. |
| | 45 | | /// </summary> |
| | 46 | | /// |
| | 47 | | /// <param name="eventBatch">The set of event data to send.</param> |
| | 48 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 49 | | /// |
| | 50 | | /// <returns>A task to be resolved on when the operation has completed.</returns> |
| | 51 | | /// |
| | 52 | | public abstract Task SendAsync(EventDataBatch eventBatch, |
| | 53 | | CancellationToken cancellationToken); |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Creates a size-constraint batch to which <see cref="EventData" /> may be added using a try-based pattern. |
| | 57 | | /// exceed the maximum allowable size of the batch, the batch will not allow adding the event and signal that |
| | 58 | | /// return value. |
| | 59 | | /// |
| | 60 | | /// Because events that would violate the size constraint cannot be added, publishing a batch will not trigger |
| | 61 | | /// attempting to send the events to the Event Hubs service. |
| | 62 | | /// </summary> |
| | 63 | | /// |
| | 64 | | /// <param name="options">The set of options to consider when creating this batch.</param> |
| | 65 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 66 | | /// |
| | 67 | | /// <returns>An <see cref="EventDataBatch" /> with the requested <paramref name="options"/>.</returns> |
| | 68 | | /// |
| | 69 | | /// <seealso cref="CreateBatchAsync(CreateBatchOptions, CancellationToken)" /> |
| | 70 | | /// |
| | 71 | | public abstract ValueTask<TransportEventBatch> CreateBatchAsync(CreateBatchOptions options, |
| | 72 | | CancellationToken cancellationToken); |
| | 73 | |
|
| | 74 | | /// <summary> |
| | 75 | | /// Closes the connection to the transport producer instance. |
| | 76 | | /// </summary> |
| | 77 | | /// |
| | 78 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | 79 | | /// |
| | 80 | | public abstract Task CloseAsync(CancellationToken cancellationToken); |
| | 81 | | } |
| | 82 | | } |