| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information.using System; |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Type used for OnShutdown property. |
| | 10 | | /// </summary> |
| | 11 | | /// <param name="e"></param> |
| | 12 | | public delegate void ShutdownNotification(Exception e); |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// Options that govern the functioning of the processor. |
| | 16 | | /// </summary> |
| | 17 | | public class EventProcessorOptions |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Construct with default options. |
| | 21 | | /// </summary> |
| 14 | 22 | | public EventProcessorOptions() |
| | 23 | | { |
| 14 | 24 | | this.MaxBatchSize = 10; |
| 14 | 25 | | this.PrefetchCount = 300; |
| 14 | 26 | | this.ReceiveTimeout = TimeSpan.FromMinutes(1); |
| 14 | 27 | | this.EnableReceiverRuntimeMetric = false; |
| 14 | 28 | | this.InvokeProcessorAfterReceiveTimeout = false; |
| 18 | 29 | | this.InitialPositionProvider = partitionId => EventPosition.FromStart(); |
| 14 | 30 | | this.ClientReceiverOptions = null; |
| 14 | 31 | | this.OnShutdown = null; |
| 14 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// The maximum number of events that will be presented to IEventProcessor.OnEventsAsync in one call. |
| | 36 | | /// Defaults to 10. |
| | 37 | | /// </summary> |
| 248 | 38 | | public int MaxBatchSize { get; set; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// The prefetch count for the Event Hubs receiver. |
| | 42 | | /// Defaults to 300. |
| | 43 | | /// </summary> |
| 22 | 44 | | public int PrefetchCount { get; set; } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// The timeout for the Event Hubs receiver. |
| | 48 | | /// Defaults to one minute. |
| | 49 | | /// </summary> |
| 30 | 50 | | public TimeSpan ReceiveTimeout { get; set; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Gets or sets a value indicating whether the runtime metric of a receiver is enabled (true) or disabled (fals |
| | 54 | | /// Defaults to false. |
| | 55 | | /// </summary> |
| 240 | 56 | | public bool EnableReceiverRuntimeMetric { get; set; } |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Determines whether IEventProcessor.OnEventsAsync is called when the Event Hubs receiver times out. |
| | 60 | | /// Set to true to get calls with empty event list. |
| | 61 | | /// Set to false to not get calls. |
| | 62 | | /// Defaults to false. |
| | 63 | | /// </summary> |
| 248 | 64 | | public bool InvokeProcessorAfterReceiveTimeout { get; set; } |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// If there is no checkpoint, the user can provide a position for the Event Hubs receiver to start at. |
| | 68 | | /// Defaults to first event available in the stream. |
| | 69 | | /// </summary> |
| 24 | 70 | | public Func<string, EventPosition> InitialPositionProvider { get; set; } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// ReceiverOptions used by the underlying Event Hubs client. |
| | 74 | | /// Defaults to null. |
| | 75 | | /// </summary> |
| 22 | 76 | | public ReceiverOptions ClientReceiverOptions { get; set; } |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// TODO -- is this needed? It's called just before SFP.RunAsync throws out/returns to user code anyway. |
| | 80 | | /// But user code won't see that until it awaits the Task, so maybe this is useful? |
| | 81 | | /// </summary> |
| 52 | 82 | | public ShutdownNotification OnShutdown { get; set; } |
| | 83 | |
|
| | 84 | | internal void NotifyOnShutdown(Exception shutdownException) |
| | 85 | | { |
| 12 | 86 | | if (this.OnShutdown != null) |
| | 87 | | { |
| 12 | 88 | | this.OnShutdown(shutdownException); |
| | 89 | | } |
| 12 | 90 | | } |
| | 91 | | } |
| | 92 | | } |