4
4
namespace Microsoft . Azure . ServiceBus
5
5
{
6
6
using System ;
7
+ using System . Collections . Generic ;
7
8
using System . Threading ;
8
9
using System . Threading . Tasks ;
10
+ using Core ;
9
11
using Primitives ;
10
12
11
13
/// <summary>Provides options associated with session pump processing using
@@ -27,6 +29,22 @@ public sealed class SessionHandlerOptions
27
29
/// <param name="exceptionReceivedHandler">A <see cref="Func{T1, TResult}"/> that is invoked during exceptions.
28
30
/// <see cref="ExceptionReceivedEventArgs"/> contains contextual information regarding the exception.</param>
29
31
public SessionHandlerOptions ( Func < ExceptionReceivedEventArgs , Task > exceptionReceivedHandler )
32
+ : this ( async args => { await exceptionReceivedHandler ( args ) ; return null ; } )
33
+ {
34
+ }
35
+
36
+ /// <summary>Initializes a new instance of the <see cref="SessionHandlerOptions" /> class.
37
+ /// Default Values:
38
+ /// <see cref="MaxConcurrentSessions"/> = 2000
39
+ /// <see cref="AutoComplete"/> = true
40
+ /// <see cref="MessageWaitTimeout"/> = 1 minute
41
+ /// <see cref="MaxAutoRenewDuration"/> = 5 minutes
42
+ /// </summary>
43
+ /// <param name="exceptionReceivedHandler">A <see cref="Func{T1, TResult}"/> that is invoked during exceptions.
44
+ /// When the exception happens during user callback, the returned dictionary is passed to <see cref="IReceiverClient.AbandonAsync"/>.
45
+ /// For other actions, the returned dictionary is ignored.
46
+ /// <see cref="ExceptionReceivedEventArgs"/> contains contextual information regarding the exception.</param>
47
+ public SessionHandlerOptions ( Func < ExceptionReceivedEventArgs , Task < IDictionary < string , object > > > exceptionReceivedHandler )
30
48
{
31
49
// These are default values
32
50
this . AutoComplete = true ;
@@ -38,7 +56,7 @@ public SessionHandlerOptions(Func<ExceptionReceivedEventArgs, Task> exceptionRec
38
56
39
57
/// <summary>Occurs when an exception is received. Enables you to be notified of any errors encountered by the session pump.
40
58
/// When errors are received calls will automatically be retried, so this is informational. </summary>
41
- public Func < ExceptionReceivedEventArgs , Task > ExceptionReceivedHandler { get ; }
59
+ public Func < ExceptionReceivedEventArgs , Task < IDictionary < string , object > > > ExceptionReceivedHandler { get ; }
42
60
43
61
/// <summary>Gets or sets the duration for which the session lock will be renewed automatically.</summary>
44
62
/// <value>The duration for which the session renew its state.</value>
@@ -92,15 +110,16 @@ public int MaxConcurrentSessions
92
110
93
111
internal int MaxConcurrentAcceptSessionCalls { get ; set ; }
94
112
95
- internal async Task RaiseExceptionReceived ( ExceptionReceivedEventArgs eventArgs )
113
+ internal async Task < IDictionary < string , object > > RaiseExceptionReceived ( ExceptionReceivedEventArgs eventArgs )
96
114
{
97
115
try
98
116
{
99
- await this . ExceptionReceivedHandler ( eventArgs ) . ConfigureAwait ( false ) ;
117
+ return await this . ExceptionReceivedHandler ( eventArgs ) . ConfigureAwait ( false ) ;
100
118
}
101
119
catch ( Exception exception )
102
120
{
103
121
MessagingEventSource . Log . ExceptionReceivedHandlerThrewException ( exception ) ;
122
+ return null ;
104
123
}
105
124
}
106
125
}
0 commit comments