From 8324f872ef3a4d0c978a9b1d062800c6a1701c12 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 01 十二月 2023 09:58:17 +0800 Subject: [PATCH] fix --- nsq/producer.go | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/nsq/producer.go b/nsq/producer.go index 2f1e947..ade2e2f 100644 --- a/nsq/producer.go +++ b/nsq/producer.go @@ -4,19 +4,30 @@ "apsClient/conf" "apsClient/pkg/logx" "apsClient/pkg/nsqclient" + "sync/atomic" ) -var producer nsqclient.Producer +var ( + producer nsqclient.Producer + initFlag int32 +) func GetProducer() nsqclient.Producer { return producer } func StopProducer() { + if !atomic.CompareAndSwapInt32(&initFlag, 1, 0) { + return + } nsqclient.DestroyProducerPool() } func initProducer() (err error) { + if !atomic.CompareAndSwapInt32(&initFlag, 0, 1) { + return nil + } + producer, err = nsqclient.NewProducer(conf.Conf.NsqConf.NsqdAddr) if err != nil { logx.Errorf("NewProducer err:%v", err) -- Gitblit v1.8.0