🎨 update nsq

This commit is contained in:
landaiqing
2024-09-29 11:07:44 +08:00
parent 83b6fb6322
commit 2769467ce2
12 changed files with 138 additions and 111 deletions

View File

@@ -8,24 +8,26 @@ import (
)
// InitNSQProducer 初始化生产者
func InitNSQProducer() *nsq.Producer {
func InitNSQProducer() {
config := nsq.NewConfig()
producer, err := nsq.NewProducer(global.CONFIG.NSQ.Addr(), config)
producer, err := nsq.NewProducer(global.CONFIG.NSQ.NsqAddr(), config)
if err != nil {
global.LOG.Error(fmt.Sprintf("InitNSQ producer error: %v", err))
return nil
return
}
return producer
producer.SetLoggerLevel(nsq.LogLevelError)
global.NSQProducer = producer
}
// InitConsumer 初始化消费者
func InitConsumer(topic string, channel string) *nsq.Consumer {
func InitConsumer(topic string) *nsq.Consumer {
config := nsq.NewConfig()
config.LookupdPollInterval = 15 * time.Second
consumer, err := nsq.NewConsumer(topic, channel, config)
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
}