| | 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.Core; |
| | 8 | | using Azure.Messaging.EventHubs.Consumer; |
| | 9 | |
|
| | 10 | | namespace Azure.Messaging.EventHubs.Processor |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Contains information about a partition that has attempted to receive an event from the Azure Event Hub |
| | 14 | | /// service in an <c>EventProcessorClient</c> context, as well as the received event, if any. It |
| | 15 | | /// also provides a way of creating a checkpoint based on the information contained in the associated event. |
| | 16 | | /// </summary> |
| | 17 | | /// |
| | 18 | | /// <seealso href="https://www.nuget.org/packages/Azure.Messaging.EventHubs.Processor" /> |
| | 19 | | /// |
| | 20 | | public struct ProcessEventArgs |
| | 21 | | { |
| | 22 | | /// <summary> |
| | 23 | | /// Indicates whether or not the arguments contain an event to be processed. In |
| | 24 | | /// the case where no event is contained, then the context and creation of |
| | 25 | | /// checkpoints are also unavailable. |
| | 26 | | /// </summary> |
| | 27 | | /// |
| | 28 | | /// <value><c>true</c> if the arguments contain an event to be processed; otherwise, <c>false</c>.</value> |
| | 29 | | /// |
| 0 | 30 | | public bool HasEvent => ((Data != null) && (Partition != null)); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// The context of the Event Hub partition this instance is associated with. |
| | 34 | | /// </summary> |
| | 35 | | /// |
| 0 | 36 | | public PartitionContext Partition { get; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// The received event to be processed. Expected to be <c>null</c> if the receive call has timed out. |
| | 40 | | /// </summary> |
| | 41 | | /// |
| | 42 | | /// <remarks> |
| | 43 | | /// Ownership of this data, including the memory that holds its <see cref="EventData.Body" />, |
| | 44 | | /// is assumed to transfer to consumers of the <see cref="ProcessEventArgs" />. It may be considered |
| | 45 | | /// immutable and is safe to access so long as the reference is held. |
| | 46 | | /// </remarks> |
| | 47 | | /// |
| 0 | 48 | | public EventData Data { get; } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// A <see cref="System.Threading.CancellationToken"/> instance to signal the request to cancel the operation. |
| | 52 | | /// </summary> |
| | 53 | | /// |
| 0 | 54 | | public CancellationToken CancellationToken { get; } |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// The callback to be called upon <see cref="UpdateCheckpointAsync" /> call. |
| | 58 | | /// </summary> |
| | 59 | | /// |
| 0 | 60 | | private Func<CancellationToken, Task> UpdateCheckpointAsyncImplementation { get; } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Initializes a new instance of the <see cref="ProcessEventArgs"/> structure. |
| | 64 | | /// </summary> |
| | 65 | | /// |
| | 66 | | /// <param name="partition">The context of the Event Hub partition this instance is associated with.</param> |
| | 67 | | /// <param name="data">The received event to be processed. Expected to be <c>null</c> if the receive call has t |
| | 68 | | /// <param name="updateCheckpointImplementation">The callback to be called upon <see cref="UpdateCheckpointAsync |
| | 69 | | /// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken"/> instance to signal the re |
| | 70 | | /// |
| | 71 | | public ProcessEventArgs(PartitionContext partition, |
| | 72 | | EventData data, |
| | 73 | | Func<CancellationToken, Task> updateCheckpointImplementation, |
| | 74 | | CancellationToken cancellationToken = default) |
| | 75 | | { |
| 0 | 76 | | Argument.AssertNotNull(updateCheckpointImplementation, nameof(updateCheckpointImplementation)); |
| | 77 | |
|
| 0 | 78 | | Partition = partition; |
| 0 | 79 | | Data = data; |
| 0 | 80 | | UpdateCheckpointAsyncImplementation = updateCheckpointImplementation; |
| 0 | 81 | | CancellationToken = cancellationToken; |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | /// <summary> |
| | 85 | | /// Updates the checkpoint for the <see cref="PartitionContext" /> and <see cref="EventData" /> associated wit |
| | 86 | | /// this event. |
| | 87 | | /// </summary> |
| | 88 | | /// |
| | 89 | | /// <param name="cancellationToken">An optional <see cref="System.Threading.CancellationToken"/> instance to sig |
| | 90 | | /// |
| | 91 | | /// <exception cref="InvalidOperationException">Occurs when <see cref="Partition" /> and <see cref="Data" /> are |
| | 92 | | /// |
| 0 | 93 | | public Task UpdateCheckpointAsync(CancellationToken cancellationToken = default) => UpdateCheckpointAsyncImpleme |
| | 94 | | } |
| | 95 | | } |