From 679086b1743e4f64e9db555ce36a53f98061e2d3 Mon Sep 17 00:00:00 2001 From: zenghongyao <873884283@qq.com> Date: Thu, 22 May 2025 12:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96kafka=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=9C=8D=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=9C=AA?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=AE=8C=EF=BC=8C=E7=AB=8B=E5=8D=B3=E9=87=8D?= =?UTF-8?q?=E5=90=AF=E5=AE=B9=E5=99=A8=E5=AF=BC=E8=87=B4=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminClient/AdminClientService.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/JiShe.CollectBus.Kafka/AdminClient/AdminClientService.cs b/modules/JiShe.CollectBus.Kafka/AdminClient/AdminClientService.cs index 918aa57..febc2bf 100644 --- a/modules/JiShe.CollectBus.Kafka/AdminClient/AdminClientService.cs +++ b/modules/JiShe.CollectBus.Kafka/AdminClient/AdminClientService.cs @@ -8,10 +8,11 @@ using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.Kafka.AdminClient; -public class AdminClientService : IAdminClientService, IDisposable, ISingletonDependency +public class AdminClientService : IAdminClientService, ISingletonDependency { private readonly ILogger _logger; private readonly KafkaOptionConfig _kafkaOptionConfig; + private readonly Lazy _lazyAdminClient; /// /// Initializes a new instance of the class. /// @@ -21,7 +22,8 @@ public class AdminClientService : IAdminClientService, IDisposable, ISingletonDe { _logger = logger; _kafkaOptionConfig = kafkaOptionConfig.Value; - Instance = GetInstance(); + //Instance = GetInstance(); + _lazyAdminClient = new Lazy(() => GetInstance()); } /// @@ -30,7 +32,7 @@ public class AdminClientService : IAdminClientService, IDisposable, ISingletonDe /// /// The instance. /// - public IAdminClient Instance { get; set; } + public IAdminClient Instance => _lazyAdminClient.Value; /// /// 创建Kafka主题 @@ -137,11 +139,6 @@ public class AdminClientService : IAdminClientService, IDisposable, ISingletonDe return metadata.Topics[0].Partitions.Count; } - public void Dispose() - { - Instance?.Dispose(); - } - /// /// Gets the instance. ///