@@ -34,15 +34,17 @@ public sealed class TestConsumer : ReceiveActor, IWithTimers
34
34
35
35
private readonly ILoggingAdapter _log = Context . GetLogger ( ) ;
36
36
private ImmutableHashSet < ( string , long ) > _processed = ImmutableHashSet < ( string , long ) > . Empty ;
37
+ private readonly bool _supportRestarts = false ;
37
38
private int _messageCount = 0 ;
38
39
39
40
public TestConsumer ( TimeSpan delay , Func < SomeAsyncJob , bool > endCondition , IActorRef endReplyTo ,
40
- IActorRef consumerController )
41
+ IActorRef consumerController , bool supportRestarts = false )
41
42
{
42
43
Delay = delay ;
43
44
EndCondition = endCondition ;
44
45
EndReplyTo = endReplyTo ;
45
46
ConsumerController = consumerController ;
47
+ _supportRestarts = supportRestarts ;
46
48
47
49
Active ( ) ;
48
50
}
@@ -73,12 +75,18 @@ private void Active()
73
75
_log . Info ( "processed [{0}] [msg: {1}] from [{2}]" , job . SeqNr , job . Msg . Payload , job . ProducerId ) ;
74
76
job . ConfirmTo . Tell ( global ::Akka . Delivery . ConsumerController . Confirmed . Instance ) ;
75
77
76
- if ( EndCondition ( job ) )
78
+ if ( EndCondition ( job ) && ( _messageCount > 0 || _supportRestarts ) )
77
79
{
78
80
_log . Debug ( "End at [{0}]" , job . SeqNr ) ;
79
81
EndReplyTo . Tell ( new Collected ( _processed . Select ( c => c . Item1 ) . ToImmutableHashSet ( ) , _messageCount + 1 ) ) ;
80
82
Context . Stop ( Self ) ;
81
83
}
84
+ else if ( ! _supportRestarts && EndCondition ( job ) )
85
+ {
86
+ // BugFix: TestConsumer was recreated by a message sent by the Sharding system, but the EndCondition was already met
87
+ // and we don't want to send another Collected that is missing some of the figures. Ignore.
88
+
89
+ }
82
90
else
83
91
{
84
92
_processed = cleanProcessed . Add ( nextMsg ) ;
@@ -181,12 +189,12 @@ public static ConsumerController.SequencedMessage<Job> SequencedMessage(string p
181
189
182
190
private static Func < SomeAsyncJob , bool > ConsumerEndCondition ( long seqNr ) => msg => msg . SeqNr >= seqNr ;
183
191
184
- public static Props PropsFor ( TimeSpan delay , long seqNr , IActorRef endReplyTo , IActorRef consumerController ) =>
185
- Props . Create ( ( ) => new TestConsumer ( delay , ConsumerEndCondition ( seqNr ) , endReplyTo , consumerController ) ) ;
192
+ public static Props PropsFor ( TimeSpan delay , long seqNr , IActorRef endReplyTo , IActorRef consumerController , bool supportsRestarts = false ) =>
193
+ Props . Create ( ( ) => new TestConsumer ( delay , ConsumerEndCondition ( seqNr ) , endReplyTo , consumerController , supportsRestarts ) ) ;
186
194
187
195
public static Props PropsFor ( TimeSpan delay , Func < SomeAsyncJob , bool > endCondition , IActorRef endReplyTo ,
188
- IActorRef consumerController ) =>
189
- Props . Create ( ( ) => new TestConsumer ( delay , endCondition , endReplyTo , consumerController ) ) ;
196
+ IActorRef consumerController , bool supportsRestarts = false ) =>
197
+ Props . Create ( ( ) => new TestConsumer ( delay , endCondition , endReplyTo , consumerController , supportsRestarts ) ) ;
190
198
191
199
public ITimerScheduler Timers { get ; set ; } = null ! ;
192
200
}
0 commit comments