kafka消费者订阅增加批量消费

This commit is contained in:
zenghongyao 2025-04-17 13:56:17 +08:00
parent 4c5f7231bf
commit 72f8222ec2

View File

@ -139,6 +139,25 @@ namespace JiShe.CollectBus.Kafka
{
var consumerService = provider.GetRequiredService<IConsumerService>();
if (attr.EnableBatch)
{
await consumerService.SubscribeBatchAsync<dynamic>(attr.Topic, async (message) =>
{
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) =>
{
try
@ -155,6 +174,8 @@ namespace JiShe.CollectBus.Kafka
});
}
}
/// <summary>
/// 处理消息