🎨 update / add nsq
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func InitIP2Region() {
|
||||
var dbPath = "ip2region/ip2region.xdb"
|
||||
var dbPath = "resource/ip2region/ip2region.xdb"
|
||||
cBuff, err := xdb.LoadContentFromFile(dbPath)
|
||||
if err != nil {
|
||||
global.LOG.Errorf("failed to load vector index from `%s`: %s\n", dbPath, err)
|
||||
|
31
core/nsq.go
Normal file
31
core/nsq.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/nsqio/go-nsq"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// InitNSQProducer 初始化生产者
|
||||
func InitNSQProducer() *nsq.Producer {
|
||||
config := nsq.NewConfig()
|
||||
producer, err := nsq.NewProducer(global.CONFIG.NSQ.Addr(), config)
|
||||
if err != nil {
|
||||
global.LOG.Error(fmt.Sprintf("InitNSQ producer error: %v", err))
|
||||
return nil
|
||||
}
|
||||
return producer
|
||||
}
|
||||
|
||||
// InitConsumer 初始化消费者
|
||||
func InitConsumer(topic string, channel 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
|
||||
}
|
||||
return consumer
|
||||
}
|
Reference in New Issue
Block a user