调整代码
This commit is contained in:
parent
87bf7feff2
commit
179b9a2e91
@ -27,7 +27,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the instance.
|
/// Gets or sets the instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The instance.
|
/// The instance.
|
||||||
@ -65,7 +65,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除Kafka主题
|
/// 删除Kafka主题
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic"></param>
|
/// <param name="topic"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -75,7 +75,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取Kafka主题列表
|
/// 获取Kafka主题列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<string>> ListTopicsAsync()
|
public async Task<List<string>> ListTopicsAsync()
|
||||||
@ -85,7 +85,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 判断Kafka主题是否存在
|
/// 判断Kafka主题是否存在
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic"></param>
|
/// <param name="topic"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -96,7 +96,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测分区是否存在
|
/// 检测分区是否存在
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic"></param>
|
/// <param name="topic"></param>
|
||||||
/// <param name="partitions"></param>
|
/// <param name="partitions"></param>
|
||||||
@ -112,7 +112,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测分区是否存在
|
/// 检测分区是否存在
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic"></param>
|
/// <param name="topic"></param>
|
||||||
/// <param name="targetPartition"></param>
|
/// <param name="targetPartition"></param>
|
||||||
@ -127,7 +127,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取主题的分区数量
|
/// 获取主题的分区数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic"></param>
|
/// <param name="topic"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -140,7 +140,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the instance.
|
/// Gets the instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IAdminClient GetInstance()
|
public IAdminClient GetInstance()
|
||||||
@ -160,7 +160,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks the topic asynchronous.
|
/// Checks the topic asynchronous.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic">The topic.</param>
|
/// <param name="topic">The topic.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -171,7 +171,7 @@ public class AdminClientService : IAdminClientService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 判断Kafka主题是否存在
|
/// 判断Kafka主题是否存在
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic">主题名称</param>
|
/// <param name="topic">主题名称</param>
|
||||||
/// <param name="numPartitions">副本数量,不能高于Brokers数量</param>
|
/// <param name="numPartitions">副本数量,不能高于Brokers数量</param>
|
||||||
|
|||||||
@ -135,6 +135,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 扩展独立线程,避免阻塞
|
||||||
|
_kafkaTaskScheduler.WorkerThreadExpansion();
|
||||||
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
||||||
{
|
{
|
||||||
var consumerKey = $"{groupId}_{string.Join("_", topics)}_{typeof(TKey).Name}_{typeof(TValue).Name}";
|
var consumerKey = $"{groupId}_{string.Join("_", topics)}_{typeof(TKey).Name}_{typeof(TValue).Name}";
|
||||||
@ -239,6 +241,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 扩展独立线程,避免阻塞
|
||||||
|
_kafkaTaskScheduler.WorkerThreadExpansion();
|
||||||
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
||||||
{
|
{
|
||||||
var consumerKey = $"{groupId}_{string.Join("_", topics)}_{typeof(Ignore).Name}_{typeof(TValue).Name}";
|
var consumerKey = $"{groupId}_{string.Join("_", topics)}_{typeof(Ignore).Name}_{typeof(TValue).Name}";
|
||||||
@ -367,6 +371,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 扩展独立线程,避免阻塞
|
||||||
|
_kafkaTaskScheduler.WorkerThreadExpansion();
|
||||||
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -538,6 +544,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 扩展独立线程,避免阻塞
|
||||||
|
_kafkaTaskScheduler.WorkerThreadExpansion();
|
||||||
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
await _kafkaPollyPipeline.KafkaPipeline.ExecuteAsync(async token =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -108,6 +108,8 @@ namespace JiShe.CollectBus.Kafka
|
|||||||
{
|
{
|
||||||
logger.LogError(ex, "Kafka任务调度异常");
|
logger.LogError(ex, "Kafka任务调度异常");
|
||||||
};
|
};
|
||||||
|
//logger.LogWarning($"kafka订阅工作线程数:{kafkaTaskScheduler.WorkerThreads},队列任务:{kafkaTaskScheduler.QueuedTasks}数");
|
||||||
|
//
|
||||||
// 订阅调度监控测试可打开
|
// 订阅调度监控测试可打开
|
||||||
//_ = Task.Factory.StartNew(async () =>
|
//_ = 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)
|
private static async Task StartConsumerAsync(IServiceProvider provider, KafkaSubscribeAttribute attr, MethodInfo method, object subscribe, ILogger<CollectBusKafkaModule> logger)
|
||||||
{
|
{
|
||||||
var consumerService = provider.GetRequiredService<IConsumerService>();
|
var consumerService = provider.GetRequiredService<IConsumerService>();
|
||||||
var kafkaTaskScheduler = provider.GetRequiredService<KafkaTaskScheduler>();
|
|
||||||
|
|
||||||
if (attr.EnableBatch)
|
if (attr.EnableBatch)
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref _threadStartCount);
|
Interlocked.Increment(ref _threadStartCount);
|
||||||
logger.LogInformation($"kafka开启线程消费:{_threadStartCount}");
|
logger.LogInformation($"kafka开启线程消费:{_threadStartCount}");
|
||||||
// 扩展独立线程,避免阻塞
|
|
||||||
kafkaTaskScheduler.WorkerThreadExpansion();
|
|
||||||
|
|
||||||
await consumerService.SubscribeBatchAsync<dynamic>(attr.Topic, async (message) =>
|
await consumerService.SubscribeBatchAsync<dynamic>(attr.Topic, async (message) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -271,8 +269,6 @@ namespace JiShe.CollectBus.Kafka
|
|||||||
{
|
{
|
||||||
Interlocked.Increment(ref _threadStartCount);
|
Interlocked.Increment(ref _threadStartCount);
|
||||||
logger.LogInformation($"kafka开启线程消费:{_threadStartCount}");
|
logger.LogInformation($"kafka开启线程消费:{_threadStartCount}");
|
||||||
// 扩展独立线程,避免阻塞
|
|
||||||
kafkaTaskScheduler.WorkerThreadExpansion();
|
|
||||||
await consumerService.SubscribeAsync<dynamic>(attr.Topic, async (message) =>
|
await consumerService.SubscribeAsync<dynamic>(attr.Topic, async (message) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user