|
|
@@ -29,7 +29,7 @@ namespace NearCardAttendance.TcpServer |
|
|
|
|
|
|
|
private readonly ServiceConfig _configService; |
|
|
|
private readonly HttpHelper _httpHelper = default!; |
|
|
|
private int _messageCount = 0; |
|
|
|
//private int _messageCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
public Server( |
|
|
@@ -87,16 +87,20 @@ namespace NearCardAttendance.TcpServer |
|
|
|
var consumeResult = kafkaConsumer.Consume(stoppingToken); |
|
|
|
if (consumeResult != null) |
|
|
|
{ |
|
|
|
_messageCount++; |
|
|
|
//_messageCount++; |
|
|
|
consumeBatchResult.Add(consumeResult); |
|
|
|
//// 30条消息为一批 |
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
if (!await ProcessBatchMessageAsync(consumeBatchResult, kafkaConsumer)) |
|
|
|
{ // 返回结果错误暂停5分钟 |
|
|
|
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken); |
|
|
|
if (consumeBatchResult.Count % 2 == 0) |
|
|
|
{ |
|
|
|
if (!await ProcessBatchMessageAsync(consumeBatchResult, kafkaConsumer)) |
|
|
|
{ // 返回结果错误暂停5分钟 |
|
|
|
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken); |
|
|
|
} |
|
|
|
} |
|
|
|
//// 30条消息为一批 |
|
|
|
#else |
|
|
|
if (_messageCount % 30 == 0) |
|
|
|
if (consumeBatchResult.Count % 30 == 0) |
|
|
|
{ |
|
|
|
if (!await ProcessBatchMessageAsync(consumeBatchResult, kafkaConsumer)) |
|
|
|
{ // 返回结果错误暂停5分钟 |
|
|
@@ -174,6 +178,7 @@ namespace NearCardAttendance.TcpServer |
|
|
|
kafkaConsumer.Commit(x); |
|
|
|
_logger.LogInformation($"完成消费:{JsonConvert.SerializeObject(x.Message.Value)}"); |
|
|
|
}); |
|
|
|
consumeBatchResult.Clear(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@@ -197,7 +202,7 @@ namespace NearCardAttendance.TcpServer |
|
|
|
BootstrapServers = _configService.KafkaServerAddress, |
|
|
|
AutoOffsetReset = AutoOffsetReset.Earliest, |
|
|
|
EnableAutoCommit = false, // 关闭自动提交偏移量 |
|
|
|
CancellationDelayMaxMs = 1//set CancellationDelayMaxMs |
|
|
|
//CancellationDelayMaxMs = 1//set CancellationDelayMaxMs |
|
|
|
}; |
|
|
|
|
|
|
|
return new ConsumerBuilder<Ignore, string>(consumerConfig) |
|
|
|