fix: Kafka consumer poison pill causes infinite retry
This commit is contained in:
@@ -33,6 +33,8 @@ public class WarningAlertService : BackgroundService
|
||||
|
||||
_logger.LogInformation("WarningAlertService started — consumer group: warning-evaluator");
|
||||
|
||||
var guard = new PoisonPillGuard("warning-evaluator", _kafkaOptions.MaxPoisonRetries, _logger);
|
||||
|
||||
try
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
@@ -58,6 +60,7 @@ public class WarningAlertService : BackgroundService
|
||||
stoppingToken);
|
||||
|
||||
consumer.Commit(result);
|
||||
guard.OnSuccess();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -65,8 +68,14 @@ public class WarningAlertService : BackgroundService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (result is not null && guard.ShouldSkip(result, ex))
|
||||
{
|
||||
consumer.Commit(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.LogError(ex,
|
||||
"WarningAlertService failed on topic={Topic} offset={Offset} — not committing",
|
||||
"WarningAlertService 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