| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.EventHubs.Processor |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Net; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// Defines the runtime options when registering an <see cref="IEventProcessor"/> interface with an EventHubConsumer |
| | 11 | | /// </summary> |
| | 12 | | public sealed class EventProcessorOptions |
| | 13 | | { |
| | 14 | | Action<ExceptionReceivedEventArgs> exceptionHandler; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Returns an EventProcessorOptions instance with all options set to the default values. |
| | 18 | | /// The default values are: |
| | 19 | | /// <para>MaxBatchSize: 10</para> |
| | 20 | | /// <para>ReceiveTimeOut: 1 minute</para> |
| | 21 | | /// <para>PrefetchCount: 300</para> |
| | 22 | | /// <para>InitialOffsetProvider: uses the last offset checkpointed, or StartOfStream</para> |
| | 23 | | /// <para>InvokeProcessorAfterReceiveTimeout: false</para> |
| | 24 | | /// </summary> |
| | 25 | | /// <value>an EventProcessorOptions instance with all options set to the default values</value> |
| | 26 | | public static EventProcessorOptions DefaultOptions |
| | 27 | | { |
| | 28 | | get |
| | 29 | | { |
| 0 | 30 | | return new EventProcessorOptions(); |
| | 31 | | } |
| | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Creates a new <see cref="EventProcessorOptions"/> object. |
| | 36 | | /// </summary> |
| 0 | 37 | | public EventProcessorOptions() |
| | 38 | | { |
| 0 | 39 | | this.MaxBatchSize = 10; |
| 0 | 40 | | this.PrefetchCount = 300; |
| 0 | 41 | | this.ReceiveTimeout = TimeSpan.FromMinutes(1); |
| 0 | 42 | | this.InitialOffsetProvider = partitionId => EventPosition.FromStart(); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Sets a handler which receives notification of general exceptions. |
| | 47 | | /// <para>Exceptions which occur while processing events from a particular Event Hub partition are delivered |
| | 48 | | /// to the onError method of the event processor for that partition. This handler is called on occasions |
| | 49 | | /// when there is no event processor associated with the throwing activity, or the event processor could |
| | 50 | | /// not be created.</para> |
| | 51 | | /// </summary> |
| | 52 | | /// <param name="exceptionHandler">Handler which is called when an exception occurs. Set to null to stop handlin |
| | 53 | | public void SetExceptionHandler(Action<ExceptionReceivedEventArgs> exceptionHandler) |
| | 54 | | { |
| 0 | 55 | | this.exceptionHandler = exceptionHandler; |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Returns the maximum size of an event batch that IEventProcessor.ProcessEventsAsync will be called with |
| | 60 | | /// </summary> |
| 0 | 61 | | public int MaxBatchSize { get; set; } |
| | 62 | |
|
| | 63 | | /// <summary> |
| | 64 | | /// Gets or sets the timeout length for receive operations. |
| | 65 | | /// </summary> |
| 0 | 66 | | public TimeSpan ReceiveTimeout { get; set; } |
| | 67 | |
|
| | 68 | | /// <summary> Gets or sets a value indicating whether the runtime metric of a receiver is enabled. </summary> |
| | 69 | | /// <value> true if a client wants to access <see cref="ReceiverRuntimeInformation"/> using <see cref="Partition |
| | 70 | | public bool EnableReceiverRuntimeMetric |
| | 71 | | { |
| 0 | 72 | | get; |
| 0 | 73 | | set; |
| | 74 | | } |
| | 75 | |
|
| | 76 | | /// <summary> |
| | 77 | | /// Gets or sets the current prefetch count for the underlying client. |
| | 78 | | /// The default is 300. |
| | 79 | | /// </summary> |
| 0 | 80 | | public int PrefetchCount { get; set; } |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// Gets or sets a delegate which is used to get the initial position for a given partition to create <see cref= |
| | 84 | | /// Delegate is invoked by passing in PartitionId and then user can return <see cref="PartitionReceiver"/> for r |
| | 85 | | /// This is only used when <see cref="Lease.Offset"/> is not provided and receiver is being created for the very |
| | 86 | | /// </summary> |
| 0 | 87 | | public Func<string, EventPosition> InitialOffsetProvider { get; set; } |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Returns whether the EventProcessorHost will call IEventProcessor.OnEvents(null) when a receive |
| | 91 | | /// timeout occurs (true) or not (false). |
| | 92 | | /// </summary> |
| 0 | 93 | | public bool InvokeProcessorAfterReceiveTimeout { get; set; } |
| | 94 | |
|
| | 95 | | /// <summary> |
| | 96 | | /// Gets or sets the web proxy. |
| | 97 | | /// A proxy is applicable only when transport type is set to AmqpWebSockets. |
| | 98 | | /// </summary> |
| | 99 | | public IWebProxy WebProxy |
| | 100 | | { |
| 0 | 101 | | get; |
| 0 | 102 | | set; |
| | 103 | | } |
| | 104 | |
|
| | 105 | | internal void NotifyOfException(string hostname, string partitionId, Exception exception, string action) |
| | 106 | | { |
| | 107 | | try |
| | 108 | | { |
| 0 | 109 | | this.exceptionHandler?.Invoke(new ExceptionReceivedEventArgs(hostname, partitionId, exception, action)); |
| 0 | 110 | | } |
| 0 | 111 | | catch |
| | 112 | | { |
| | 113 | | // NOOP, Ignore exception from notify callback. Let's avoid chain of exception notification. |
| 0 | 114 | | } |
| 0 | 115 | | } |
| | 116 | | } |
| | 117 | | } |