kafka消费者订阅增加批量消费
This commit is contained in:
parent
4c5f7231bf
commit
72f8222ec2
@ -139,20 +139,41 @@ namespace JiShe.CollectBus.Kafka
|
||||
{
|
||||
var consumerService = provider.GetRequiredService<IConsumerService>();
|
||||
|
||||
await consumerService.SubscribeAsync<dynamic>(attr.Topic, async (message) =>
|
||||
if (attr.EnableBatch)
|
||||
{
|
||||
try
|
||||
await consumerService.SubscribeBatchAsync<dynamic>(attr.Topic, async (message) =>
|
||||
{
|
||||
// 处理消息
|
||||
return await ProcessMessageAsync(message, method, subscribe);
|
||||
}
|
||||
catch (ConsumeException ex)
|
||||
try
|
||||
{
|
||||
// 处理消息
|
||||
return await ProcessMessageAsync(message, method, subscribe);
|
||||
}
|
||||
catch (ConsumeException ex)
|
||||
{
|
||||
// 处理消费错误
|
||||
logger.LogError($"kafka批量消费异常:{ex.Message}");
|
||||
}
|
||||
return await Task.FromResult(false);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await consumerService.SubscribeAsync<dynamic>(attr.Topic, async (message) =>
|
||||
{
|
||||
// 处理消费错误
|
||||
logger.LogError($"kafka消费异常:{ex.Message}");
|
||||
}
|
||||
return await Task.FromResult(false);
|
||||
});
|
||||
try
|
||||
{
|
||||
// 处理消息
|
||||
return await ProcessMessageAsync(message, method, subscribe);
|
||||
}
|
||||
catch (ConsumeException ex)
|
||||
{
|
||||
// 处理消费错误
|
||||
logger.LogError($"kafka消费异常:{ex.Message}");
|
||||
}
|
||||
return await Task.FromResult(false);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user