This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
landaiqing 2769467ce2 🎨 update nsq
2024-09-29 11:07:44 +08:00

34 lines
799 B
Go

package core
import (
"fmt"
"github.com/nsqio/go-nsq"
"schisandra-cloud-album/global"
"time"
)
// InitNSQProducer 初始化生产者
func InitNSQProducer() {
config := nsq.NewConfig()
producer, err := nsq.NewProducer(global.CONFIG.NSQ.NsqAddr(), config)
if err != nil {
global.LOG.Error(fmt.Sprintf("InitNSQ producer error: %v", err))
return
}
producer.SetLoggerLevel(nsq.LogLevelError)
global.NSQProducer = producer
}
// InitConsumer 初始化消费者
func InitConsumer(topic string) *nsq.Consumer {
config := nsq.NewConfig()
config.LookupdPollInterval = 15 * time.Second
consumer, err := nsq.NewConsumer(topic, "channel", config)
if err != nil {
fmt.Printf("InitNSQ consumer error: %v\n", err)
return nil
}
consumer.SetLoggerLevel(nsq.LogLevelError)
return consumer
}