10
10
11
11
namespace RabbitMQ . Stream . Client . Reliable ;
12
12
13
+ public class ReconnectingArgs : EventArgs
14
+ {
15
+ public ReconnectingArgs ( bool isReconnecting )
16
+ {
17
+ IsReconnecting = isReconnecting ;
18
+ }
19
+
20
+ public bool IsReconnecting { get ; }
21
+ }
22
+
13
23
public record ReliableConfig
14
24
{
15
25
public IReconnectStrategy ReconnectStrategy { get ; set ; }
16
26
public StreamSystem StreamSystem { get ; }
17
27
public string Stream { get ; }
18
28
29
+
30
+ public delegate void ReconnectingEventHandler ( object sender , ReconnectingArgs e ) ;
31
+
32
+ public event ReconnectingEventHandler Reconnecting ;
33
+
34
+ internal virtual void OnReconnecting ( ReconnectingArgs e )
35
+ {
36
+ Reconnecting ? . Invoke ( this , e ) ;
37
+ }
38
+
19
39
protected ReliableConfig ( StreamSystem streamSystem , string stream )
20
40
{
21
41
if ( string . IsNullOrWhiteSpace ( stream ) )
@@ -41,6 +61,15 @@ public abstract class ReliableBase
41
61
protected bool _isOpen ;
42
62
protected bool _inReconnection ;
43
63
64
+ internal delegate void ReconnectingEventHandler ( object sender , ReconnectingArgs e ) ;
65
+
66
+ internal event ReconnectingEventHandler Reconnecting ;
67
+
68
+ protected virtual void OnReconnecting ( ReconnectingArgs e )
69
+ {
70
+ Reconnecting ? . Invoke ( this , e ) ;
71
+ }
72
+
44
73
protected abstract ILogger BaseLogger { get ; }
45
74
46
75
internal async Task Init ( IReconnectStrategy reconnectStrategy )
@@ -105,6 +134,7 @@ private async Task Init(bool boot, IReconnectStrategy reconnectStrategy)
105
134
protected async Task TryToReconnect ( IReconnectStrategy reconnectStrategy )
106
135
{
107
136
_inReconnection = true ;
137
+ OnReconnecting ( new ReconnectingArgs ( true ) ) ;
108
138
try
109
139
{
110
140
switch ( await reconnectStrategy . WhenDisconnected ( ToString ( ) ) . ConfigureAwait ( false ) && _isOpen )
@@ -122,6 +152,7 @@ protected async Task TryToReconnect(IReconnectStrategy reconnectStrategy)
122
152
finally
123
153
{
124
154
_inReconnection = false ;
155
+ OnReconnecting ( new ReconnectingArgs ( false ) ) ;
125
156
}
126
157
}
127
158
@@ -143,7 +174,8 @@ internal async Task HandleMetaDataMaybeReconnect(string stream, StreamSystem sys
143
174
await Task . Delay ( 500 ) . ConfigureAwait ( false ) ;
144
175
if ( await system . StreamExists ( stream ) . ConfigureAwait ( false ) )
145
176
{
146
- BaseLogger . LogInformation ( "Meta data update stream: {StreamIdentifier}. The stream still exists. Client: {Identity}" ,
177
+ BaseLogger . LogInformation (
178
+ "Meta data update stream: {StreamIdentifier}. The stream still exists. Client: {Identity}" ,
147
179
stream ,
148
180
ToString ( )
149
181
) ;
0 commit comments