fix: 解決kafka會遺漏commit已處理的meesage的問題
This commit is contained in:
parent
33638bdd36
commit
33606ca9eb
@ -64,8 +64,9 @@ public class KafkaConsumer : BackgroundService
|
|||||||
|
|
||||||
await BulkInsertToDatabaseAsync(buffer, stoppingToken);
|
await BulkInsertToDatabaseAsync(buffer, stoppingToken);
|
||||||
|
|
||||||
var latestOffset = buffer.Last();
|
var offsets = buffer.GroupBy(msg => msg.TopicPartition)
|
||||||
consumer.Commit(latestOffset);
|
.Select(g => new TopicPartitionOffset(g.Key, g.Last().Offset + 1)).ToList();
|
||||||
|
consumer.Commit(offsets);
|
||||||
|
|
||||||
_logger.LogInformation($"✅ [成功] 已寫入 {buffer.Count} 筆資料至 PostgreSQL。");
|
_logger.LogInformation($"✅ [成功] 已寫入 {buffer.Count} 筆資料至 PostgreSQL。");
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user