fix: Kafka consumer poison pill causes infinite retry
This commit is contained in:
@@ -39,6 +39,8 @@ public class SepsisEngineService : BackgroundService
|
||||
_logger.LogInformation(
|
||||
"SepsisEngineService started — consumer group: sepsis-engine (qSOFA screening only)");
|
||||
|
||||
var guard = new PoisonPillGuard("sepsis-engine", _kafkaOptions.MaxPoisonRetries, _logger);
|
||||
|
||||
try
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
@@ -68,6 +70,7 @@ public class SepsisEngineService : BackgroundService
|
||||
evt.EncounterId, evt.ObservationCode, evt.Value);
|
||||
|
||||
consumer.Commit(result);
|
||||
guard.OnSuccess();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -75,8 +78,14 @@ public class SepsisEngineService : BackgroundService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (result is not null && guard.ShouldSkip(result, ex))
|
||||
{
|
||||
consumer.Commit(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.LogError(ex,
|
||||
"SepsisEngine failed on topic={Topic} offset={Offset} — not committing",
|
||||
"SepsisEngine failed on topic={Topic} offset={Offset} — will retry",
|
||||
result?.Topic, result?.Offset.Value);
|
||||
await Task.Delay(2000, stoppingToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user