File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Threading ;
3
+
4
+ namespace EasyNetQ
5
+ {
6
+ // TODO Should migrate Timeout from ushort to TimeSpan
7
+ internal static class ConnectionConfigurationExtensions
8
+ {
9
+ public static TimeSpan GetTimeout ( this ConnectionConfiguration configuration )
10
+ {
11
+ return configuration . Timeout == 0 ? Timeout . InfiniteTimeSpan : TimeSpan . FromSeconds ( configuration . Timeout ) ;
12
+ }
13
+ }
14
+ }
Original file line number Diff line number Diff line change @@ -42,9 +42,7 @@ public void InvokeChannelAction(Action<IModel> channelAction)
42
42
{
43
43
Preconditions . CheckNotNull ( channelAction , "channelAction" ) ;
44
44
45
- var timeout = configuration . Timeout . Equals ( 0 )
46
- ? TimeBudget . Infinite ( )
47
- : TimeBudget . Start ( TimeSpan . FromSeconds ( configuration . Timeout ) ) ;
45
+ var timeout = TimeBudget . Start ( configuration . GetTimeout ( ) ) ;
48
46
49
47
var retryTimeoutMs = MinRetryTimeoutMs ;
50
48
while ( ! timeout . IsExpired ( ) )
Original file line number Diff line number Diff line change @@ -228,9 +228,14 @@ public void Publish(
228
228
var rawMessage = produceConsumeInterceptor . OnProduce ( new RawMessage ( messageProperties , body ) ) ;
229
229
if ( connectionConfiguration . PublisherConfirms )
230
230
{
231
- var timeout = TimeBudget . Start ( TimeSpan . FromSeconds ( connectionConfiguration . Timeout ) ) ;
232
- while ( ! timeout . IsExpired ( ) )
231
+ var timeout = TimeBudget . Start ( connectionConfiguration . GetTimeout ( ) ) ;
232
+ while ( true )
233
233
{
234
+ if ( timeout . IsExpired ( ) )
235
+ {
236
+ throw new TimeoutException ( $ "Publish timed out after { connectionConfiguration . Timeout } seconds") ;
237
+ }
238
+
234
239
var confirmsWaiter = clientCommandDispatcher . Invoke ( model =>
235
240
{
236
241
var properties = model . CreateBasicProperties ( ) ;
@@ -338,9 +343,14 @@ public virtual async Task PublishAsync(
338
343
var rawMessage = produceConsumeInterceptor . OnProduce ( new RawMessage ( messageProperties , body ) ) ;
339
344
if ( connectionConfiguration . PublisherConfirms )
340
345
{
341
- var timeout = TimeBudget . Start ( TimeSpan . FromSeconds ( connectionConfiguration . Timeout ) ) ;
342
- while ( ! timeout . IsExpired ( ) )
346
+ var timeout = TimeBudget . Start ( connectionConfiguration . GetTimeout ( ) ) ;
347
+ while ( true )
343
348
{
349
+ if ( timeout . IsExpired ( ) )
350
+ {
351
+ throw new TimeoutException ( $ "Publish timed out after { connectionConfiguration . Timeout } seconds") ;
352
+ }
353
+
344
354
var confirmsWaiter = await clientCommandDispatcher . InvokeAsync ( model =>
345
355
{
346
356
var properties = model . CreateBasicProperties ( ) ;
You can’t perform that action at this time.
0 commit comments