调整代码

This commit is contained in:
zenghongyao 2025-05-23 14:01:33 +08:00
parent 87bf7feff2
commit 179b9a2e91
3 changed files with 21 additions and 17 deletions

View File

@ -27,7 +27,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// Gets or sets the instance.
/// Gets or sets the instance.
/// </summary>
/// <value>
/// The instance.
@ -65,7 +65,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 删除Kafka主题
/// 删除Kafka主题
/// </summary>
/// <param name="topic"></param>
/// <returns></returns>
@ -75,7 +75,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 获取Kafka主题列表
/// 获取Kafka主题列表
/// </summary>
/// <returns></returns>
public async Task<List<string>> ListTopicsAsync()
@ -85,7 +85,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 判断Kafka主题是否存在
/// 判断Kafka主题是否存在
/// </summary>
/// <param name="topic"></param>
/// <returns></returns>
@ -96,7 +96,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 检测分区是否存在
/// 检测分区是否存在
/// </summary>
/// <param name="topic"></param>
/// <param name="partitions"></param>
@ -112,7 +112,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 检测分区是否存在
/// 检测分区是否存在
/// </summary>
/// <param name="topic"></param>
/// <param name="targetPartition"></param>
@ -127,7 +127,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 获取主题的分区数量
/// 获取主题的分区数量
/// </summary>
/// <param name="topic"></param>
/// <returns></returns>
@ -140,7 +140,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// Gets the instance.
/// Gets the instance.
/// </summary>
/// <returns></returns>
public IAdminClient GetInstance()
@ -160,7 +160,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// Checks the topic asynchronous.
/// Checks the topic asynchronous.
/// </summary>
/// <param name="topic">The topic.</param>
/// <returns></returns>
@ -171,7 +171,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
}
/// <summary>
/// 判断Kafka主题是否存在
/// 判断Kafka主题是否存在
/// </summary>
/// <param name="topic">主题名称</param>
/// <param name="numPartitions">副本数量不能高于Brokers数量</param>

View File

@ -135,6 +135,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
{
try
{
// 扩展独立线程,避免阻塞
_kafkaTaskScheduler.WorkerThreadExpansion();
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
{
var consumerKey = $"{groupId}_{string.Join("_", topics)}_{typeof(TKey).Name}_{typeof(TValue).Name}";
@ -239,6 +241,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
{
try
{
// 扩展独立线程,避免阻塞
_kafkaTaskScheduler.WorkerThreadExpansion();
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
{
var consumerKey = $"{groupId}_{string.Join("_", topics)}_{typeof(Ignore).Name}_{typeof(TValue).Name}";
@ -367,6 +371,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
{
try
{
// 扩展独立线程,避免阻塞
_kafkaTaskScheduler.WorkerThreadExpansion();
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
{
@ -538,6 +544,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
{
try
{
// 扩展独立线程,避免阻塞
_kafkaTaskScheduler.WorkerThreadExpansion();
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
{

View File

@ -108,6 +108,8 @@ namespace JiShe.CollectBus.Kafka
{
logger.LogError(ex, "Kafka任务调度异常");
};
//logger.LogWarning($"kafka订阅工作线程数{kafkaTaskScheduler.WorkerThreads},队列任务:{kafkaTaskScheduler.QueuedTasks}数");
//
// 订阅调度监控测试可打开
//_ = Task.Factory.StartNew(async () =>
// {
@ -235,15 +237,11 @@ namespace JiShe.CollectBus.Kafka
private static async Task StartConsumerAsync(IServiceProvider provider, KafkaSubscribeAttribute attr, MethodInfo method, object subscribe, ILogger<CollectBusKafkaModule> logger)
{
var consumerService = provider.GetRequiredService<IConsumerService>();
var kafkaTaskScheduler = provider.GetRequiredService<KafkaTaskScheduler>();
if (attr.EnableBatch)
{
Interlocked.Increment(ref _threadStartCount);
logger.LogInformation($"kafka开启线程消费:{_threadStartCount}");
// 扩展独立线程,避免阻塞
kafkaTaskScheduler.WorkerThreadExpansion();
await consumerService.SubscribeBatchAsync<dynamic>(attr.Topic, async (message) =>
{
try
@ -271,8 +269,6 @@ namespace JiShe.CollectBus.Kafka
{
Interlocked.Increment(ref _threadStartCount);
logger.LogInformation($"kafka开启线程消费:{_threadStartCount}");
// 扩展独立线程,避免阻塞
kafkaTaskScheduler.WorkerThreadExpansion();
await consumerService.SubscribeAsync<dynamic>(attr.Topic, async (message) =>
{
try